Borrar filtros
Borrar filtros

How to save solid-color figure to tif file?

1 visualización (últimos 30 días)
KAE
KAE el 27 de Mzo. de 2018
Comentada: Ameer Hamza el 26 de Abr. de 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?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by