Imwrite with display range

9 vues (au cours des 30 derniers jours)
Aleksander
Aleksander le 27 Août 2013
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

Réponses (1)

Walter Roberson
Walter Roberson le 27 Août 2013
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 commentaires
Image Analyst
Image Analyst le 28 Août 2013
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 le 23 Juin 2021
Modifié(e) : Felipe Assunção le 24 Juin 2021
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!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Filtering and Enhancement dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by