Converting Map Figure into TIFF file without background

5 次查看(过去 30 天)
Hello Community!
So I have a 300 by 500 by 1 data set that corresponds to a scalar colormap plot. In the figure, I hid all of the titles, axes, etc., so that the figure only shows the colormap. I would like to save this plot such that the image retains its 300 by 500 pixel dimensions, and it is lossless.
However, when saving as a TIFF file, MATLAB adds a white background, making the image larger in size.
I tried using imwrite (which allows me to save images without the background), however I am unable to save as a TIFF because my data type is incompatible. Upon converting to a double type data, the resulting TIFF image showed a binary map. I have tried other file types, but they are too lossy (I can only choose bitdepth of 8, when 16 or higher would be preferred).
Any suggestions or advice would be greatly appreciated!
  2 个评论
Edmund Han
Edmund Han 2017-11-1
The original data class is single. The range is from approximately -100 to 700, with 4 decimal places.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-11-1
However, you mention colormap, from a 300 by 500 by 1 data set. That implies you are using pseudocolor and that you want the color image saved. You probably did not build of colormap of more than 256 colors, but you might have.
Under your circumstances what I would do is use mat2gray() to scale your data to the range 0 to 1.
If your colormap is 256 entries or less, use im2uint8() on the scaled data, and then you can imwrite() that, passing in a copy of your color map as the second parameter.
If your colormap is more than 256 entries, use im2uint16() on the scaled data, and then you can imwrite() that, passing in a copy of your color map as the second parameter. I find that PNG is a bit better for working with colormaps that are more than 256 but less than 65536 entries, as PNG is fine with writing just as many entries as needed (some other formats need one entry for each possible binary value.)
What does not seem to be possible is to create a color image while storing your original float data -- not unless one creates multiple data-sets in the same file and uses one for display and the other for the data. (TIFF does have a pseudocolor mode but it is for indexed images with integer values stored.)
  1 个评论
Edmund Han
Edmund Han 2017-11-2
Hey Walter,
Thank you so much for your help! Not only did you respond so quickly, but you even made great suggestions that allowed to do more than I thought I could. I really appreciate it!
Regards, Edmund

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by