Displaying 16 bit images

100 次查看(过去 30 天)
Jiayun Liu
Jiayun Liu 2022-12-8
编辑: Stephen23 2022-12-9
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.

采纳的回答

DGM
DGM 2022-12-8
编辑:DGM 2022-12-8
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.
  8 个评论
Stephen23
Stephen23 2022-12-9
编辑:Stephen23 2022-12-9
"How can you display 64 bit data with 8 bit data through linear scaling?
Type conversions are inherently lossy: if you convert from 16 bit to 8 bit then you will lose information. This is why people who work with images professionally do not switch between data types and colorspaces, but select one that has enough range for their work.
"There are 52 bit to encode the fraction part, how can you separate 0.00001 and 0.000011 with 8 bit?"
You cannot see the difference and your monitor definitely cannot display the difference, so why would it matter?
It is very very unlikely that your image source can even record data with such precision (unless you happen to be working with the James Webb Space Telescope).
Lets have a look at those values:
255*(0.000011-0.00001)
ans = 2.5500e-04
According to a quick internet search, humans can distinguish around 1 million colors, fewer than the 16.7 million provided by 8 bit sRGB images (or around the same if we are being very generous). The values you are asking about have a difference a thousand times smaller than those of 8-bit TrueColor sRGB, well beyond any human visual capability.
I do not know where you got your alien monitor technology from, but please send me some! No human could distinguish between the values that you gave, so presumably you are also an alien. Welcome to earth.
Instead of tilting against windmills, perhaps some reading on image sensor noise, image compression algorithms, image colorspaces, and human perceptual limits would help.
"Shouldn't the internal mapping map the double precision data to 8 bit before it can display?"
Why?
Jiayun Liu
Jiayun Liu 2022-12-9
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by