Imwrite outputs white image

조회 수: 13 (최근 30일)
Sean
Sean 2014년 8월 19일
댓글: DGM 2022년 11월 9일
Hi,
I am trying to save a slice from an image stack using imwrite but it writes blank (white) images. I suspect it is an issue with imwrite assuming a dynamic range of [0 1] while I would like to use []. Is there a way to get around this?
Example code:
for a=1:10
imshow(Ibf(:,:,a),[0 1]) %Image displays blank (completely white)
imshow(Ibf(:,:,a),[]) %Image displays correctly
imwrite(Ibf(:,:,a),'filename.jpg')); %Output is white images
end
Note: Ibf is an image stack in grayscale
  댓글 수: 1
DGM
DGM 2022년 11월 9일
The problem is an issue of the expected scale. Regardless of class, if the image is properly scaled for its class, then it will both display and write as expected. If you have a floating point image that's improperly-scaled (i.e. not unit-scale), then it won't be written or displayed correctly.
This is almost certainly a consequence of casting an integer-class image as 'double' without scaling it accordingly. Either rescale the floating-point image to unit-scale, or cast it to the class that corresponds to its current scale. If you're going to work with intermediate images in an improperly-scaled state, that's fine, but you'll have to account for it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2014년 8월 19일
If Ibf is a normal uint8 RGB image in the range 0-255 then of course saying it should display [0,1] as 0-255 will send 0 to 0 and 1 and anything more than that to 255. What is the class of Ibf? Is it double or uint8? If it's uint8, the imwrite should write out correctly as you have it.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by