Displaying 16 bit images

35 views (last 30 days)
Jiayun Liu
Jiayun Liu on 8 Dec 2022
Edited: Stephen23 on 9 Dec 2022
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.

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.
Jiayun Liu
Jiayun Liu on 9 Dec 2022
Guess I misunderstood what you said earlier about the linear scaling as direct mapping. Your explanation exactly answered my question. I just feel that going from higher to lower bit, it can't be a 1-to-1 mapping. I just do not know how they do this many to one mapping. It would seem that matlab uses something similar or exactly the function 'im2uint8' when displaying data with higher bit depth.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!