Imwrite with display range
8 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
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
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 Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!