Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getframe help

55 views
Skip to first unread message

Allen

unread,
Mar 9, 2004, 2:09:32 PM3/9/04
to
Hi, I am trying to use getframe to compose a movie in matlab, however
when I use imshow or image to plot the image and then use getframe to
catch the image, sometimes if I switch to other windows to do other
work, getframe will capture the content in the active window instead
of the shown image. Is there any way to solve this problem? I have
tried to use the image hadle or default but nothing worked out.

Btw, my OS is windows 2000, and I use matlab 6.5.0R13.

Thanks and your clue is highly appeciated!

Allen

Brett Shoelson

unread,
Mar 9, 2004, 2:53:46 PM3/9/04
to

"Allen" <ar...@cytokinetics.com> wrote in message news:7ly03ijrvsy9@legacy...

Why don't you show a snippet of your code to let us see how you're updating
your image and how you're calling getframe?
Brett


Allen

unread,
Mar 9, 2004, 4:35:33 PM3/9/04
to
Hi, Brett, here is the code:

Assume fn is the cell array of image filenames

for i=1:size(fn, 1)
im = imread(fn{i});
h=figure; imshow(im);
text(100, 100, num2str(i));
mov(i) = getframe(h);
close;
end;

movie2avi(mov,'test.avi', 'compression', 'indeo5');

The reason for me to use imshow is because I want to put text
annotations on the image. If we only deal with image data, we may use
im2frame without any problem.

Now if you switch windows, some frame might capture the content in the
active window.

Thanks!

Allen

Brett Shoelson

unread,
Mar 9, 2004, 5:54:16 PM3/9/04
to

"Allen" <ar...@cytokinetics.com> wrote in message news:f2ht7zri6aut@legacy...

Allen,
First, do you really need to create a new figure for each image you display?
Far better, in most cases, to do something like:

h = figure;
ax = axes;
image = imshow(imread(fn{ii}));

for ii=1:size(fn,1)
set(image,'cdata', imread(fn{ii}));
text(100,100, num2str(ii))
mov = addframe(mov,getframe(image));
end

Cheers,
Brett


Herbert Ramoser

unread,
Mar 10, 2004, 1:52:21 AM3/10/04
to

Even better is to avoid the use of getframe at all (it causes problems
when the figure is partly occluded):

[...]
mov = addframe(mov, h);
[...]

If you use addframe like this it is even possible to make the figure
invisible.

-Herbert

Brett Shoelson

unread,
Mar 10, 2004, 1:38:40 PM3/10/04
to

"Herbert Ramoser" <herbert_D...@gmx.net> wrote in message
news:c2mdua$1tcltg$1...@ID-148798.news.uni-berlin.de...

Nice, Herbert! Didn't know you could do that.
Brett


Allen

unread,
Mar 10, 2004, 8:46:26 PM3/10/04
to
Hi, Brett and Herbert, many thanks to you for the help! I greatly
appreciate what you have suggested. Cool.......

Allen

Randy Wilson

unread,
May 10, 2004, 9:53:29 PM5/10/04
to
When I use:

mov_file = avifile(handles.mov_name);
mov_fig = figure('visible','off');
mov_axs = axes;
colormap(gray);
set(mov_fig,'DoubleBuffer','on');

imagesc(pix,'parent',movie_axs);
movie_file = addframe(mov_file,mov_fig);

instead of:

imagesc(pix)
F = getframe(gca);
movie_file = addframe(mov_file,F);

The movies run in the background, BUT there is the gray border around
the movie and the axes are labeled. This is not there when I use
getframe and display the figure. Is there anyway to remove this gray
border, axis labels..etc and NOT display the figure?

Tony

unread,
May 11, 2004, 6:56:45 AM5/11/04
to
That should work, I don't see a problem.

Steven Lord

unread,
May 11, 2004, 8:55:32 AM5/11/04
to

Note that in the first code you're capturing the figure and putting it in
the AVI file, while in the second code you're capturing the axis and putting
it in the AVI file. The gray border in the first movie is the figure
background that's located outside the axes. Try passing the axis handle to
the call to ADDFRAME in the first case, or try changing the axes Units
and/or Position properties to cause the axes to fill the entire figure.

--
Steve Lord
sl...@mathworks.com


Randy Wilson

unread,
May 12, 2004, 10:32:59 AM5/12/04
to
On Tue, 11 May 2004 08:55:32 -0400, Steven Lord wrote:
>Randy Wilson wrote:
>> When I use:
>>
>> mov_file = avifile(handles.mov_name);
>> mov_fig = figure('visible','off');
>> mov_axs = axes;
>> colormap(gray);
>> set(mov_fig,'DoubleBuffer','on');
>>
>> imagesc(pix,'parent',movie_axs);
>> movie_file = addframe(mov_file,mov_axs);

>>
>> instead of:
>>
>> imagesc(pix)
>> F = getframe(gca);
>> movie_file = addframe(mov_file,F);
>>
>> The movies run in the background, BUT there is the gray border
around
>> the movie and the axes are labeled. This is not there when I use
>> getframe and display the figure. Is there anyway to remove this
gray
>> border, axis labels..etc and NOT display the figure?
>
>Note that in the first code you're capturing the figure and putting
it in
>the AVI file, while in the second code you're capturing the axis and
putting
>it in the AVI file. The gray border in the first movie is the figure
>background that's located outside the axes. Try passing the axis
handle to
>the call to ADDFRAME in the first case, or try changing the axes
Units
>and/or Position properties to cause the axes to fill the entire
figure.
>
>--
>Steve Lord
>sl...@mathworks.com

That still does not seem to work, I get almost the exact same thing
when using:

mov_file = avifile(handles.mov_name);
mov_fig = figure('visible','off');
mov_axs = axes;
colormap(gray);
set(mov_fig,'DoubleBuffer','on');

imagesc(pix,'parent',movie_axs);
movie_file = addframe(mov_file,mov_axs);

Randy Wilson

unread,
May 12, 2004, 9:21:50 PM5/12/04
to

anyone?

Herbert Ramoser

unread,
May 13, 2004, 2:29:46 AM5/13/04
to

Since you are displaying an image you might consider using
subplot('position', [0 0 1 1]), axis off, and truesize to show only the
image data.

-Herbert

0 new messages