1

I have a code that takes a video and separate it into frames.I would like to NOT keep all the frames, instead i want each frame to be displayed in the previous figure. The code looks like these:

 filename = uigetfile; %get the file name
obj = VideoReader(filename);
nFrames=obj.NumberOfFrames;
 for k = 1 : nFrames  
this_frame = read(obj, k);
thisfig = figure();
thisax = axes('Parent', thisfig);
image(this_frame, 'Parent', thisax);
title(thisax, sprintf('Frame #%d', k));

Another thing that's important is that i calculate intensities from each figure as it comes but i don't need to save the figure after i save the data. Can anyone help me and tell me what i should change in my code? Thanks!

Maayan
  • 149
  • 1
  • 9

2 Answers2

1

Not sure whether it is a full solution, but one improvement in your code would definately be to move the figure() command out of the loop.

Maybe this is already sufficient, or maybe you need to assign your image command to a handle as described in this related question , allowing you to remove the last plotted image before you plot a new one.

Community
  • 1
  • 1
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
  • When i take it outside of the loop i get only one figure at the end but it's not the last one and the title and the numbers on the axes are blurry. – Maayan Sep 11 '13 at 08:38
  • @Maayan Thanks for accepting my answer. However, to help future visitors even more, I would like to ask you to post the final solution that you have found. – Dennis Jaheruddin Sep 11 '13 at 08:58
1
    filename = uigetfile; %get the file name
    obj = VideoReader(filename);
    nFrames=obj.NumberOfFrames;
    thisfig = figure();
 for k = 1 : nFrames  
    this_frame = read(obj, k);
    thisax = axes('Parent', thisfig);
    image(this_frame, 'Parent', thisax);
    if k==nFrames
    title(thisax, sprintf('Frame #%d', k));
    end
end
Maayan
  • 149
  • 1
  • 9