imshow()将白色图像显示为灰色图像 [英] imshow() displays a white image for a grey image

查看:293
本文介绍了imshow()将白色图像显示为灰色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计算出的图像的值在0到255之间.当我使用imageview()时,该图像正确显示为灰度级,但是当我要保存此图像或用imshow显示时,我有一个白色图片,或者有时到处都是黑色像素:

I have computed an image with values between 0 and 255. When I use imageview(), the image is correctly displayed, in grey levels, but when I want to save this image or display it with imshow, I have a white image, or sometimes some black pixels here and there:

在imageview()中:

Whereas with imageview():

有人可以帮我吗?

推荐答案

Matlab期望double类型的图像在0..1范围内,而uint8类型的图像在0..255范围内.您可以自己转换范围(但会在过程中更改值),进行显式转换(并可能降低精度)或指示Matlab使用图像矩阵中的最小值和最大值作为白色和黑色值,以缩放到何时可视化.

Matlab expects images of type double to be in the 0..1 range and images that are uint8 in the 0..255 range. You can convert the range yourself (but change values in the process), do an explicit cast (and potentially loose precision) or instruct Matlab to use the minimum and maximum value found in the image matrix as the white and black value to scale to when visualising.

请参见下面的示例,其中在Matlab中提供了uint8图像:

See the following example with an uint8 image present in Matlab:

im = imread('moon.tif');
figure; imshow(im);
figure; imshow(double(im));
figure; imshow(double(im), []);
figure; imshow(im2double(im));

这篇关于imshow()将白色图像显示为灰色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆