質問

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.

役に立ちましたか?

解決

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.

他のヒント

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.

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top