Imwrite with display range

6 ビュー (過去 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 Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by