When I write the image it appears black

被刻印的时光 ゝ 提交于 2019-12-11 08:47:30

问题


I have a program that returns a grayscale image. But, when I try to write the image, it appears totally black. Why is that? How can I write the image and get the expected result?

Thanks.


回答1:


First check on the type of your data. You can cast the type of the data by example double() or uint16() etc. (Check the help for typecasting). Here is an example how you rescale your values to the intensity-range of uint16, unsigned integers with ~65k possible different values. The casting of course leads to less precision of the intensity values.

new_img(:,:) = uint16((new_img(:,:)./max(max(new_img(:,:),[],1)))*65536);

Afterwards you should be able to write the data to your file.




回答2:


Make sure that your grayscaled image is of the right class. Furthermore check the values in the generated image. If they're simply too low all will appear black. If you can provide more specific information it might be possible to give a more elaborate answer.




回答3:


if you're working on a binary image(before being converted to gray) and you about to convert it to gray-scale, then you suddenly change the range of pixels from [0, 1] to [0, 255]. so the value '1' in binary image is totally white but in gray-scale image is almost black.

try this:

img = imread('image_name.jpg');
imshow(img*50)

it make you sure that you image is black or just its pixel-values aren't appropriate.



来源:https://stackoverflow.com/questions/19949141/when-i-write-the-image-it-appears-black

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