Black image getting saved while using imsave

5 次查看(过去 30 天)
Hey,
I am trying to save a part of a 16 bit image using imsave as a TIFF file. When I save the image (using imsave()), it is showing up as a black image on my computer's image viewer (Windows Photo Viewer). Initially I thought that Photo Viewer might not be supporting 16 bit images, but that doesn't make much sense because I can see the full image before I import it into MATLAB for cropping.
When I import the saved TIFF file to MATLAB, I can use imagesc() to view the image but not imshow(image, [0 2^16-1]). When I checked the maximum value of the imported image, it's only around 957. So, I think what's going on is that since the pixel values are just between 0 and 957, and the image viewer has 2^16 levels, the image isn't showing up properly. Is there anyway I can save the image such that it shows up on my viewer?
Thanks in advance.
Thank you.

回答(1 个)

Adam
Adam 2015-3-13
Just scale it up to use the full 16-bit range before you save it.
i.e. multiply by 65535/957
but replacing the hard-coded numbers with something calculated for reusablility.
  2 个评论
Mathews John
Mathews John 2015-3-16
Thank you.
The scaling, as it was supposed to, worked. I do not understand what you meant by 'replacing the hard-coded numbers with something calculated for reusablility' Could you give an example?
Adam
Adam 2015-3-16
Well, obviously 957 is not going to be correct for every image you may use so you should replace that code with code that takes its value from the maximum of your image.
Likewise the 65535 is only correct for a 16-bit image. If you may be handling images of other data types then this value should be taken appropriately for the data type.

请先登录,再进行评论。

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by