Filter löschen
Filter löschen

How to save solid-color figure to tif file?

1 Ansicht (letzte 30 Tage)
KAE
KAE am 27 Mär. 2018
Kommentiert: Ameer Hamza am 26 Apr. 2018
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?

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 26 Apr. 2018
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 Kommentare
KAE
KAE am 26 Apr. 2018
Works perfectly, thanks. I didn't think of getframe.
Ameer Hamza
Ameer Hamza am 26 Apr. 2018
You are welcome.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by