フィルターのクリア

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 Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by