Thread Subject: Axes control in GUI

Subject: Axes control in GUI

From: Gheorghe

Date: 4 Jan, 2008 07:49:09

Message: 1 of 5

Hi,

I have a toy example of a video player implemented in a GUI.
It works fine, but for some reason, the second frame is
shown in a new figure (then the playback happens in the
original axes). What am I doing wrong?

Code extracts are below. Thanks in advance,
Gheorghe

Here is the initialization code (in _OpeningFcn....):

%%
handles.vr = varargin{1};
handles.timer = timer('Period',0.5, ...
    'ExecutionMode', 'fixedSpacing', ...
    'timerFcn', {@fcnOnTimer, handles.vr, handles.axes1 } );
handles.state = 0; % i.e. stopped
guidata(hObject, handles);

here is the result of pressing the Play button:

%%
handles.state = 1 - handles.state;
if handles.state,
    start(handles.timer);
else
    stop(handles.timer);
end
guidata(hObject,handles);

and finally here is the callback function:

function varargout = fcnOnTimer(obj,event, vr, cax)
imshow(getnext(vr), 'Parent', cax)

Subject: Axes control in GUI

From: Huy

Date: 4 Jan, 2008 08:27:39

Message: 2 of 5

Instead of using imshow function to display each frame,
updating 'CData' property of image obj in the current axes
is the better and faster way, and it maybe resolve your
problem.

function varargout = fcnOnTimer(obj,event, vr, cax)
imobj = findobj('parent',cax,'type','image');
set(imobj,'Cdata',getnext(vr));
%%imshow(getnext(vr), 'Parent', cax)

And you could change 'cax' to 'imobj' in the inputs of
fcnOnTimer function

function varargout = fcnOnTimer(obj,event, vr, imobj)
set(imobj,'Cdata',getnext(vr));

Anh Huy Phan
RIKEN - BSI


"Gheorghe " <gheorghe.postelnicu@gmail.com> wrote in
message <flkodl$fkb$1@fred.mathworks.com>...
> Hi,
>
> I have a toy example of a video player implemented in a
GUI.
> It works fine, but for some reason, the second frame is
> shown in a new figure (then the playback happens in the
> original axes). What am I doing wrong?
>
> Code extracts are below. Thanks in advance,
> Gheorghe
>
> Here is the initialization code (in _OpeningFcn....):
>
> %%
> handles.vr = varargin{1};
> handles.timer = timer('Period',0.5, ...
> 'ExecutionMode', 'fixedSpacing', ...
> 'timerFcn', {@fcnOnTimer, handles.vr, handles.axes1
 } );
> handles.state = 0; % i.e. stopped
> guidata(hObject, handles);
>
> here is the result of pressing the Play button:
>
> %%
> handles.state = 1 - handles.state;
> if handles.state,
> start(handles.timer);
> else
> stop(handles.timer);
> end
> guidata(hObject,handles);
>
> and finally here is the callback function:
>
> function varargout = fcnOnTimer(obj,event, vr, cax)
> imshow(getnext(vr), 'Parent', cax)

Subject: Axes control in GUI

From: Gheorghe

Date: 4 Jan, 2008 09:03:19

Message: 3 of 5

Hi Huy,

Thanks for the reply! I think your suggestion makes a lot of
sense and after implementing it, the new figure doesn't pop
up anymore. However, the image doesn't refresh anymore -
although I added a refreshdata especially trying to tackle
this (please see below code). Any suggestions?

function varargout = fcnOnTimer(obj,event, vr, cax)
imobj = findobj('parent',cax, 'type', 'image');
set(imobj, 'Cdata', getnext(vr))
refreshdata(imobj)
%imshow(getnext(vr), 'Parent', cax)

"Huy " <phananhhuy@mathworks.com> wrote in message
<flkqlr$s2o$1@fred.mathworks.com>...
> Instead of using imshow function to display each frame,
> updating 'CData' property of image obj in the current axes
> is the better and faster way, and it maybe resolve your
> problem.
>
> function varargout = fcnOnTimer(obj,event, vr, cax)
> imobj = findobj('parent',cax,'type','image');
> set(imobj,'Cdata',getnext(vr));
> %%imshow(getnext(vr), 'Parent', cax)
>
> And you could change 'cax' to 'imobj' in the inputs of
> fcnOnTimer function
>
> function varargout = fcnOnTimer(obj,event, vr, imobj)
> set(imobj,'Cdata',getnext(vr));
>
> Anh Huy Phan
> RIKEN - BSI
>
>
> "Gheorghe " <gheorghe.postelnicu@gmail.com> wrote in
> message <flkodl$fkb$1@fred.mathworks.com>...
> > Hi,
> >
> > I have a toy example of a video player implemented in a
> GUI.
> > It works fine, but for some reason, the second frame is
> > shown in a new figure (then the playback happens in the
> > original axes). What am I doing wrong?
> >
> > Code extracts are below. Thanks in advance,
> > Gheorghe
> >
> > Here is the initialization code (in _OpeningFcn....):
> >
> > %%
> > handles.vr = varargin{1};
> > handles.timer = timer('Period',0.5, ...
> > 'ExecutionMode', 'fixedSpacing', ...
> > 'timerFcn', {@fcnOnTimer, handles.vr, handles.axes1
> } );
> > handles.state = 0; % i.e. stopped
> > guidata(hObject, handles);
> >
> > here is the result of pressing the Play button:
> >
> > %%
> > handles.state = 1 - handles.state;
> > if handles.state,
> > start(handles.timer);
> > else
> > stop(handles.timer);
> > end
> > guidata(hObject,handles);
> >
> > and finally here is the callback function:
> >
> > function varargout = fcnOnTimer(obj,event, vr, cax)
> > imshow(getnext(vr), 'Parent', cax)
>

Subject: Axes control in GUI

From: Huy

Date: 4 Jan, 2008 10:02:42

Message: 4 of 5

Hi Gheorghe,

I'm sorry not to clarify in detail. To use this way, you
need to display the first frame in the axes. If not, this
object imobj is empty.

imobj = findobj('parent',cax, 'type', 'image');

Here is an example which displays the image sequences
'AT3_1m4_01.tif' 'AT3_1m4_02.tif' 'AT3_1m4_03.tif'
(existing in the folder: MATLAB\toolbox\images\imdemos)

im1 = imread('AT3_1m4_01.tif');
imobj = imshow(im1);
pause(1)

im2 = imread('AT3_1m4_02.tif');
set(imobj,'Cdata',im2)
pause(1)

im3 = imread('AT3_1m4_03.tif');
set(imobj,'Cdata',im3)

Return to your function, it could be modified as below

function varargout = fcnOnTimer(obj,event, vr, cax)
imobj = findobj('parent',cax, 'type', 'image');
if ~isempty(imobj)
    set(imobj, 'Cdata', getnext(vr))
else
    axes(cax)
    imshow(getnext(vr))
end


Anh Huy Phan
RIKEN - BSI


"Gheorghe " <gheorghe.postelnicu@gmail.com> wrote in message
<flkson$58j$1@fred.mathworks.com>...
> Hi Huy,
>
> Thanks for the reply! I think your suggestion makes a lot
of
> sense and after implementing it, the new figure doesn't pop
> up anymore. However, the image doesn't refresh anymore -
> although I added a refreshdata especially trying to tackle
> this (please see below code). Any suggestions?
>
> function varargout = fcnOnTimer(obj,event, vr, cax)
> imobj = findobj('parent',cax, 'type', 'image');
> set(imobj, 'Cdata', getnext(vr))
> refreshdata(imobj)
> %imshow(getnext(vr), 'Parent', cax)
>
> "Huy " <phananhhuy@mathworks.com> wrote in message
> <flkqlr$s2o$1@fred.mathworks.com>...
> > Instead of using imshow function to display each frame,
> > updating 'CData' property of image obj in the current
axes
> > is the better and faster way, and it maybe resolve your
> > problem.
> >
> > function varargout = fcnOnTimer(obj,event, vr, cax)
> > imobj = findobj('parent',cax,'type','image');
> > set(imobj,'Cdata',getnext(vr));
> > %%imshow(getnext(vr), 'Parent', cax)
> >
> > And you could change 'cax' to 'imobj' in the inputs of
> > fcnOnTimer function
> >
> > function varargout = fcnOnTimer(obj,event, vr, imobj)
> > set(imobj,'Cdata',getnext(vr));
> >
> > Anh Huy Phan
> > RIKEN - BSI
> >
> >
> > "Gheorghe " <gheorghe.postelnicu@gmail.com> wrote in
> > message <flkodl$fkb$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > I have a toy example of a video player implemented in
a
> > GUI.
> > > It works fine, but for some reason, the second frame is
> > > shown in a new figure (then the playback happens in the
> > > original axes). What am I doing wrong?
> > >
> > > Code extracts are below. Thanks in advance,
> > > Gheorghe
> > >
> > > Here is the initialization code (in _OpeningFcn....):
> > >
> > > %%
> > > handles.vr = varargin{1};
> > > handles.timer = timer('Period',0.5, ...
> > > 'ExecutionMode', 'fixedSpacing', ...
> > > 'timerFcn', {@fcnOnTimer, handles.vr, handles.axes1
> > } );
> > > handles.state = 0; % i.e. stopped
> > > guidata(hObject, handles);
> > >
> > > here is the result of pressing the Play button:
> > >
> > > %%
> > > handles.state = 1 - handles.state;
> > > if handles.state,
> > > start(handles.timer);
> > > else
> > > stop(handles.timer);
> > > end
> > > guidata(hObject,handles);
> > >
> > > and finally here is the callback function:
> > >
> > > function varargout = fcnOnTimer(obj,event, vr, cax)
> > > imshow(getnext(vr), 'Parent', cax)
> >
>

Subject: Axes control in GUI

From: Adam

Date: 18 Feb, 2008 19:08:01

Message: 5 of 5

thanks that worked great here is the code i used to test it
incase someone wants to do the same

    pic=rand(480,640);
    
    imobj = findobj(handles.axes1, 'type', 'image');
    if ~isempty(imobj)
    set(imobj, 'Cdata', pic)
    else
    axes(handles.axes1)
    imagesc(pic)
    end

Tags for this Thread

Everyone's Tags:

gui

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
gui Gheorghe 4 Jan, 2008 04:05:06
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com