Convert 32 bit image to 8 bit image

61 Ansichten (letzte 30 Tage)
windmill
windmill am 16 Dez. 2020
Beantwortet: Image Analyst am 21 Dez. 2020
Hey,
I have an .tif grayscale image with a bit depth of 32. I want to convert it from 32 bit to 8 bit. I tried using mat2gray, but every time I tried displaying the image after converting it, it didn't look at all like it before. It was all black with only a few barely visible brighter spots. Does anyone know ho to properly perform the transformation?

Antworten (3)

Walter Roberson
Walter Roberson am 16 Dez. 2020
Bearbeitet: Walter Roberson am 16 Dez. 2020
IMG8 = im2uint8(IMG);

James Tursa
James Tursa am 16 Dez. 2020
I'm assuming you just need to scale things. E.g.,
X = your image (as a unit32?)
Y = uint8( double(X) * ((2^8-1)/(2^32-1)) );
There may be a MATLAB function for this, but I am not familiar with the image manipulation functions.

Image Analyst
Image Analyst am 21 Dez. 2020
The mat2gray() approach would be this:
To turn it into a double image:
% Scale so min -> 0, and max -> 1.0
dblImage = mat2gray(uint32Image);
imshow(dblImage);
To turn it into an 8 bit uint8 image with the lowest gray level a proprotionally scaled value
% Divide by max so min = something, and max -> 255. Something is not 0 unless the min was 0.
uint8Image = uint8(255 * double(uint32Image) / max(uint32Image(:)));
imshow(uint8Image);
To turn it into an 8 bit uint8 image with the lowest gray level at 0
% Scale so min -> 0, and max -> 255
uint8Image = uint8(255 * mat2gray(uint32Image));
imshow(uint8Image);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by