Displaying 16 bit images
35 views (last 30 days)
Show older comments
If I have an image with 16 bit depth, does matlab convert it into 8 bit before display if I use imshow? If I convert the data from 16 bit to 8 bit using uint8, I don't get the same image.
0 Comments
Accepted Answer
DGM
on 8 Dec 2022
Edited: DGM
on 8 Dec 2022
It's hard to know what you're doing wrong exactly since you didn't give a code example, but I'm going to guess.
Imshow() will display images of various classes so long as the image is scaled correctly with respect to its current class. If you have uint16 data cast as double, it won't be displayed as expected.
Alternatively, if you did something like this, you'll probably lose most of the image data due to truncation.
inpict = imread('myskeleton.tif'); % uint16 [0 65535]
inpict = uint8(inpict); % truncate everything above 255
When changing an image to another class, scale is important. Tools like uint8(), double(), etc. only cast the data. Tools like im2uint8(), im2double(), etc. rescale the data to fit the expected range of the destination class.
inpict = im2uint8(inpict); % rescale [0 65535] to fit within [0 255]
That avoids data truncation, and it keeps things scaled as other tools (imshow(), imwrite()) expect it.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!