Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Convert figure to image or frame (without getframe)

Subject: Convert figure to image or frame (without getframe)

From: Andrew

Date: 5 Oct, 2010 10:04:04

Message: 1 of 4

Dear fellow Matlab users

I have been struggling with what I assumed would be a fairly simple problem for some time now, and hope that one of you may be able to assist me.

The software I am developing is an image processing tool; it reads an .avi file into the matlab environment does various thresholding and object recongition procedures and then creates an output video.

On each iteration of a loop the code reads the current frame, plots it invisibly on a figure and then overlays simple line and scatter plots on the image to identify and highlight various features.

What I need to do is convert this figure to either an image or a frame so that I can then insert it into my movie structure.

I want to do this invisibly - so as far as I know I can not use getframe (even with fig prop 'Visible', 'off').

To date I have been saving the current figure as a .tiff to the save directory, then reading it back into the matlab environment as an image. This does work, but obviously is not very efficient - and furthermore is simply not a practicle solution for the final product I have in mind.

Please help dear colleagues! I feel there must be a way to convert a figure to an image or frame within the matlab environment without having the figure window popup every time.

Subject: Convert figure to image or frame (without getframe)

From: Steve Eddins

Date: 5 Oct, 2010 12:40:40

Message: 2 of 4

On 10/5/2010 6:04 AM, Andrew wrote:
> Dear fellow Matlab users
>
> I have been struggling with what I assumed would be a fairly simple
> problem for some time now, and hope that one of you may be able to
> assist me.
>
> The software I am developing is an image processing tool; it reads an
> .avi file into the matlab environment does various thresholding and
> object recongition procedures and then creates an output video.
>
> On each iteration of a loop the code reads the current frame, plots it
> invisibly on a figure and then overlays simple line and scatter plots on
> the image to identify and highlight various features.
>
> What I need to do is convert this figure to either an image or a frame
> so that I can then insert it into my movie structure.
>
> I want to do this invisibly - so as far as I know I can not use getframe
> (even with fig prop 'Visible', 'off').
>
> To date I have been saving the current figure as a .tiff to the save
> directory, then reading it back into the matlab environment as an image.
> This does work, but obviously is not very efficient - and furthermore is
> simply not a practicle solution for the final product I have in mind.
>
> Please help dear colleagues! I feel there must be a way to convert a
> figure to an image or frame within the matlab environment without having
> the figure window popup every time.

Try the hardcopy function. Although it is undocumented, there are some
solutions describing its use in the Support area of mathworks.com. For
example:

http://www.mathworks.com/support/solutions/en/data/1-3NMHJ5/?solution=1-3NMHJ5

---
Steve Eddins
http://blogs.mathworks.com/steve

Subject: Convert figure to image or frame (without getframe)

From: Andrew

Date: 5 Oct, 2010 13:09:04

Message: 3 of 4

Steve Eddins <Steve.Eddins@mathworks.com> wrote in message <i8f6c8$s26$1@fred.mathworks.com>...
> On 10/5/2010 6:04 AM, Andrew wrote:
> > Dear fellow Matlab users
> >
> > I have been struggling with what I assumed would be a fairly simple
> > problem for some time now, and hope that one of you may be able to
> > assist me.
> >
> > The software I am developing is an image processing tool; it reads an
> > .avi file into the matlab environment does various thresholding and
> > object recongition procedures and then creates an output video.
> >
> > On each iteration of a loop the code reads the current frame, plots it
> > invisibly on a figure and then overlays simple line and scatter plots on
> > the image to identify and highlight various features.
> >
> > What I need to do is convert this figure to either an image or a frame
> > so that I can then insert it into my movie structure.
> >
> > I want to do this invisibly - so as far as I know I can not use getframe
> > (even with fig prop 'Visible', 'off').
> >
> > To date I have been saving the current figure as a .tiff to the save
> > directory, then reading it back into the matlab environment as an image.
> > This does work, but obviously is not very efficient - and furthermore is
> > simply not a practicle solution for the final product I have in mind.
> >
> > Please help dear colleagues! I feel there must be a way to convert a
> > figure to an image or frame within the matlab environment without having
> > the figure window popup every time.
>
> Try the hardcopy function. Although it is undocumented, there are some
> solutions describing its use in the Support area of mathworks.com. For
> example:
>
> http://www.mathworks.com/support/solutions/en/data/1-3NMHJ5/?solution=1-3NMHJ5
>
> ---
> Steve Eddins
> http://blogs.mathworks.com/steve


many thanks, I'll have a look and see if I can get anywhere with this new tip

Subject: Convert figure to image or frame (without getframe)

From: Andrew

Date: 6 Oct, 2010 11:24:06

Message: 4 of 4




Many thanks; hardcopy worked a treat! I will play around a little to tweak my particular implementation of it, but it works and I am already seeing a significant improvement in processing demand.

Tags for this Thread

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.

Contact us