Matlab imshow doesn't plot correctly but imshowpair does

感情迁移 提交于 2019-12-01 11:39:03

问题


I have imported an image. I have parsed it to double precision and performed some filtering on it.

When I plot the result with imshow, the double image is too dark. But when I use imshowpair to plot the original and the final image, both images are correctly displayed.

I have tried to use uint8, im2uint8, multiply by 255 and then use those functions, but the only way to obtain the correct image is using imshowpair.

What can I do?


回答1:


It sounds like a problem where the majority of your intensities / colour data are outside the dynamic range of what is accepted for imshow when showing double data.

I also see that you're using im2double, but im2double simply converts the image to double and if the image is already double, nothing happens. It's probably because of the way you are filtering the images. Are you doing some sort of edge detection? The reason why you're getting dark images is probably because the majority of your intensities are negative, or are hovering around 0. imshow whe displaying double type images assumes that the dynamic range of intensities is [0,1].

Therefore, one way to resolve your problem is to do:

imshow(im,[]);

This shifts the display so that range so the smallest value is mapped to 0, and the largest to 1.

If you'd like a more permanent solution, consider creating a new output variable that does this for you:

out = (im - min(im(:))) / (max(im(:)) - min(im(:)));

This will perform the same shifting that imshow does when displaying data for you. You can now just do:

imshow(out);


来源:https://stackoverflow.com/questions/33702810/matlab-imshow-doesnt-plot-correctly-but-imshowpair-does

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