Converting Map Figure into TIFF file without background

조회 수: 5 (최근 30일)
Edmund Han
Edmund Han 2017년 11월 1일
댓글: Edmund Han 2017년 11월 2일
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
Walter Roberson
Walter Roberson 2017년 11월 1일
What is the data type of your data, and the range?
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