Thread Subject: Poor quality when saving figures as images

Subject: Poor quality when saving figures as images

From: Brad

Date: 6 Nov, 2009 02:16:03

Message: 1 of 5

I have a routine that processes some data and creates figures as it goes, and I want to know how to programatically save the figures as images, and get the exact same results as I would get via the File > Save As... menu dialog from the figure window.

Currently, if I save a figure through the File > Save As... menu, I'm happy with the way it looks (just like it looks on screen). But if I try to programatically save the same figures using saveas or print like below, they look bad in my opinion. I lose the background color I specified, the aspect ratio isn't what I specified, the font size is huge, etc.
     
saveas(gcf,path,'png');
-OR-
print(gcf,'-dpng',path);

How can I avoid the ugly "default" look and get the same results as when manually saving via the menu?

Thanks!

Subject: Poor quality when saving figures as images

From: Oliver Woodford

Date: 6 Nov, 2009 03:39:02

Message: 2 of 5

"Brad " <wooleverbradj@johndeere.com> wrote in message <hd00t3$o98$1@fred.mathworks.com>...
> I have a routine that processes some data and creates figures as it goes, and I want to know how to programatically save the figures as images, and get the exact same results as I would get via the File > Save As... menu dialog from the figure window.
>
> Currently, if I save a figure through the File > Save As... menu, I'm happy with the way it looks (just like it looks on screen). But if I try to programatically save the same figures using saveas or print like below, they look bad in my opinion. I lose the background color I specified, the aspect ratio isn't what I specified, the font size is huge, etc.
>
> saveas(gcf,path,'png');
> -OR-
> print(gcf,'-dpng',path);
>
> How can I avoid the ugly "default" look and get the same results as when manually saving via the menu?
>
> Thanks!

Hi

I don't know about the same as the Save as.. option, but export_fig generates an image of a figure as it appears on screen. You find it at:
http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig

HTH,
Oliver

Subject: Poor quality when saving figures as images

From: roger

Date: 6 Nov, 2009 11:10:55

Message: 3 of 5

On Nov 6, 3:16 am, "Brad " <wooleverbr...@johndeere.com> wrote:
> I have a routine that processes some data and creates figures as it goes, and I want to know how to programatically save the figures as images, and get the exact same results as I would get via the File > Save As... menu dialog from the figure window.
>
> Currently, if I save a figure through the File > Save As... menu, I'm happy with the way it looks (just like it looks on screen).  But if I try to programatically save the same figures using saveas or print like below, they look bad in my opinion.  I lose the background color I specified, the aspect ratio isn't what I specified, the font size is huge, etc.
>
> saveas(gcf,path,'png');  
> -OR-
> print(gcf,'-dpng',path);
>
> How can I avoid the ugly "default" look and get the same results as when manually saving via the menu?
>
> Thanks!

try playing with the papertype, papersize, paperposition etc.
properties of the figure, these will allow you to control the size of
the printed image. There is a print option that lets you choose
whether to include the background colors or not, i forgot what it is
called but it should be in the print documentation.

Subject: Poor quality when saving figures as images

From: Brad

Date: 6 Nov, 2009 18:13:02

Message: 4 of 5

"Oliver Woodford" <o.j.woodford.98@cantab.net> wrote in message <hd05om$j3k$1@fred.mathworks.com>...
> "Brad " <wooleverbradj@johndeere.com> wrote in message <hd00t3$o98$1@fred.mathworks.com>...
> > I have a routine that processes some data and creates figures as it goes, and I want to know how to programatically save the figures as images, and get the exact same results as I would get via the File > Save As... menu dialog from the figure window.
> >
> > Currently, if I save a figure through the File > Save As... menu, I'm happy with the way it looks (just like it looks on screen). But if I try to programatically save the same figures using saveas or print like below, they look bad in my opinion. I lose the background color I specified, the aspect ratio isn't what I specified, the font size is huge, etc.
> >
> > saveas(gcf,path,'png');
> > -OR-
> > print(gcf,'-dpng',path);
> >
> > How can I avoid the ugly "default" look and get the same results as when manually saving via the menu?
> >
> > Thanks!
>
> Hi
>
> I don't know about the same as the Save as.. option, but export_fig generates an image of a figure as it appears on screen. You find it at:
> http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig
>
> HTH,
> Oliver

Thanks! This is doing pretty much exactly what I wanted.

Subject: Poor quality when saving figures as images

From: Jkarretero Jkarretero

Date: 10 Jun, 2010 02:37:05

Message: 5 of 5

I have written a function that does what you are asking for:

imageSize is a vector of 2 values indicating width & height.
fileName and imageSize are optionals.

function saveImage (figureHandle, fileName, imageSize)

    if ~exist('fileName','var'), fileName='image.png'; end

    if exist('imageSize','var')
        % Adjust figure to size required
        set(figureHandle, 'Position', [1 100 imageSize(1) imageSize(2)]);
    end

    % Convert figure to image
    set(figureHandle, 'Visible', 'on');
    frame = getframe(figureHandle);
    set(figureHandle,'Visible','off');
    imagen = frame.cdata;

    % Save the image to disk
    imwrite(imagen, fileName);
end

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
saveas Jkarretero Jkarretero 9 Jun, 2010 22:39:17
image Jkarretero Jkarretero 9 Jun, 2010 22:39:17
figure Jkarretero Jkarretero 9 Jun, 2010 22:39:17
size Jkarretero Jkarretero 9 Jun, 2010 22:39:17
look Jkarretero Jkarretero 9 Jun, 2010 22:39:17
rssFeed for this Thread

Contact us at files@mathworks.com