필터 지우기
필터 지우기

How to save solid-color figure to tif file?

조회 수: 1 (최근 30일)
KAE
KAE 2018년 3월 27일
댓글: Ameer Hamza 2018년 4월 26일
I am trying to save a tif image with a uniform color to see how that color appears in various applications (PhotoShop etc). Below I create a figure, set its background to green, and save it as a tif file. But when I open the tif file in PhotoShop or Windows Photos it's white, so I've lost the green background of the figure. And the second example also fails when I make a large green axis; the tif file appears white. I believe I am incorrectly stating the command line save command to create the tif file. How do I save an image file showing a solid region of color with no white border, i.e. filled to the image edge?
f1 = figure;
set(f1, 'color', 'g') % Make the figure background green
saveas(gcf, 'green background1.tif') % When this tif file is opened, it appears white not green
Below changing the axis color also results in a white tif file when opened,
f2 = figure;
hAx1 = subplot(1,1,1); % Make one big axis
set(hAx1,'Unit','normalized','Position',[0 0 1 1], ... % set the axes to full screen
'xgrid', 'off', 'ygrid', 'off', 'xtick', [], 'ytick', []); % Keep the color uniform (no grid lines)
set(hAx1, 'color', 'g'); % Make the axis green
saveas(gcf, 'green background2.tif') % When this tif file is opened, it also appears white not green
But when I choose File > Save As from the f2 figure window, and choose to save to a tif file, the resulting tif file does appear green! How can I do this from the command line?

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 4월 26일
if all you want is a solid color tif, you can do it using the following
image = zeros(500, 500, 3);
image(:,:,2) = 1;
imwrite(image, 'test.tif');
As for figure you can use following method to preserve color
f1 = figure;
set(f1, 'color', 'g') % Make the figure background green
image = getframe(f1);
imwrite(image.cdata, 'test.tif');
  댓글 수: 2
KAE
KAE 2018년 4월 26일
Works perfectly, thanks. I didn't think of getframe.
Ameer Hamza
Ameer Hamza 2018년 4월 26일
You are welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by