|
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)
> >
>
|