问题描述
以下代码段会产生 double
。
f = imread('C:\Users\Administrator\Desktop\2.tif');
h = double(f);
figure;
imshow(h);
然而,这个其他代码片段会产生 uint8
。
whereas, this other code snippet results a uint8
image.
f = imread('C:\Users\Administrator\Desktop\2.tif');
figure;
imshow(f);
显示这两个数字时,这两个图像的显示结果使用 imshow
是不同的,但这种差异背后的原因是什么?
While displaying these two figures, the displayed results of these two images using imshow
are different, but what is the reason behind this difference?
推荐答案
类型<$ c的图像假设$ c> double 的值介于0和1之间,而 uint8
假设图像的值介于0到255之间。由于你的 double
数据包含0到255之间的值(因为您只是将其转换为 double
并且不执行任何缩放),由于大多数值大于1,它将显示为大部分为白色。
Images of type double
are assumed to have values between 0 and 1 and uint8
images are assumed to have values between 0 and 255. Since your double
data contains values between 0 and 255 (since you simply cast it as a double
and don't perform any scaling), it will appear as mostly white since most values are greater than 1.
您可以使用第二个输入 imshow
表示您要忽略此假设并自动将显示缩放到数据的动态范围
You can use the second input to imshow
to indicate that you would like to ignore this assumption and automatically scale the display to the dynamic range of the data
imshow(h, [])
或者你可以规范化 double
在displayi之前使用 mat2gray
的版本图像
Or you can normalize the double
version using mat2gray
prior to displaying the image
h = mat2gray(h);
imshow(h)
这篇关于使用imshow时uint8和double图像之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!