Convert 32 bit image to 8 bit image
45 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (4)
James Tursa
le 16 Déc 2020
Modifié(e) : DGM
le 11 Mai 2024
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.
0 commentaires
Walter Roberson
le 16 Déc 2020
Modifié(e) : Walter Roberson
le 16 Déc 2020
IMG8 = im2uint8(IMG);
1 commentaire
DGM
le 11 Mai 2024
IPT im2uint8() does not support anything other than the six standard IPT image classes.
inpict = imread('peppers_uint32.tiff.fakeextension.txt'); % RGB, uint32
inpict = im2uint8(inpict);
Image Analyst
le 21 Déc 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);
0 commentaires
DGM
le 11 Mai 2024
Modifié(e) : DGM
le 11 Mai 2024
@James Tursa's answer is correct, but there are tools that can do the job -- just not within IPT.
MIMT imcast() is to IPT im2double() and im2uint8() what cast() is to double() and uint8(). The fact that it's parametric is normally the appeal, but what's important here is that it actually supports a broader range of numeric classes than IPT tools do.
inpict = imread('my32bimage.tiff'); % uint32 or int32
inpict = imcast(inpict,'uint8'); % uint8
Easy as that. No math to remember. No conditional wrappers to write. Scale and contrast are preserved. Properly-scaled image in, properly-scaled image out.
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!