Imwrite with display range

조회 수: 9 (최근 30일)
Aleksander
Aleksander 2013년 8월 27일
편집: Felipe Assunção 2021년 6월 24일
I want to save image as *.tiff with its *.tfw for georeference in ArcMap. The problem occures because I need my image to look excatly like the image that I create with imshow in figure, where I set the display range.
Is it possible to imwrite image with prefered display range?
thanks

답변 (1개)

Walter Roberson
Walter Roberson 2013년 8월 27일
No, that is not an option for imwrite().
You can getframe() the image to grab a copy of it exactly as displayed. Or you can calculate the mapped image and write that.
minD = min(YourData(:));
maxD = max(YourData(:));
mapped_image = (double(YourData) - minD) ./ (maxD - minD);
ncmap = size(colormap, 1);
mapped_image = mapped_image .* ncmap;
if ncmap == 2
mapped_image = mapped_image >= 0.5; %logical
elseif ncmap <= 256
mapped_image = uint8(mapped_image);
else
mapped_image = uint16(mapped_image);
end
imwrite( mapped_image, 'YourData.tif' )
This assumes that you used imshow(YourData, []) . If you provided a specific data range then,
minD = Lo; %you used imshow(YourData, [Lo, High])
maxD = High;
Subtle issue here: the Lo value you supply is greater than the data minimum, or the High value you supply is less than the data minimum, then the numeric mapping (before the conversion to logical or uint8 or uint16) will have some values that are negative, or greater than the number of entries in the color map. The code I have chosen for datatype conversion clips the intensities so that nothing is out of range after datatype conversion. uint8() and uint16() "saturate to 0" for values < 0, and "saturate to maximum" for values too large.
  댓글 수: 3
Image Analyst
Image Analyst 2013년 8월 28일
There is a function called imadjust() in the Image Processing Toolbox that does a linear histogram stretch of an image automatically, or between values that you specify.
Felipe Assunção
Felipe Assunção 2021년 6월 23일
편집: Felipe Assunção 2021년 6월 24일
I was trying to save my superpixels labels in .pgm format like showed in imshow(labels, [0 199]) but with imwrite is not possible! So, I discovered the answer that I could use
imshow(labels,[0 199])
labelsRange = getframe;
imwrite(labelsRange.cdata, labels.pgm)
Thanks a lot!

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

카테고리

Help CenterFile Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by