Imwrite with display range

9 visualizaciones (últimos 30 días)
Aleksander
Aleksander el 27 de Ag. de 2013
Editada: Felipe Assunção el 24 de Jun. de 2021
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

Respuestas (1)

Walter Roberson
Walter Roberson el 27 de Ag. de 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 comentarios
Image Analyst
Image Analyst el 28 de Ag. de 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 el 23 de Jun. de 2021
Editada: Felipe Assunção el 24 de Jun. de 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!

Iniciar sesión para comentar.

Categorías

Más información sobre Image Filtering and Enhancement en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by