imshow() displays a white image for a grey image

爱⌒轻易说出口 提交于 2019-12-02 10:54:39

问题


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:

Whereas with imageview():

Can some one help me?


回答1:


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.

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));



回答2:


I think that you should use imshow(uint8(image)); on the image before displaying it.



来源:https://stackoverflow.com/questions/22428938/imshow-displays-a-white-image-for-a-grey-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!