VIDEOFIG(NUM_FRAMES, @REDRAW_FUNC) creates a figure with a horizontal scrollbar and shortcuts to scroll automatically. The scroll range is 1 to NUM_FRAMES. The function REDRAW_FUNC(F) is called to redraw at scroll position F (for example, REDRAW_FUNC can show the frame F of a video).
This can be used not only to play and analyze standard videos, but it also lets you place any custom Matlab plots and graphics on top.
Jiro posted a great example on the Pick of the Week blog, along with a nice GIF animation so you can see it in motion:
Place this in a file called "redraw.m":
imshow(['AT3_1m4_' num2str(frame, '%02.0f') '.tif'])
Then from a script or the command line, call:
The images "AT3_1m4_01.tif" ... "AT3_1m4_10.tif" are part of the Image
Processing Toolbox and there's no need to download them elsewhere.
Change the redraw function to visualize the contour of a single cell:
im = imread(['AT3_1m4_' num2str(frame, '%02.0f') '.tif']);
slice = im(210:310, 210:340);
[ys, xs] = find(slice < 50 | slice > 100);
pos = 210 + median([xs, ys]);
siz = 3.5 * std([xs, ys]);
imshow(im), hold on
rectangle('Position',[pos - siz/2, siz], 'EdgeColor','g', 'Curvature',[1, 1])
The keyboard shortcuts are:
Enter (Return) -- play/pause video (25 frames-per-second default).
Backspace -- play/pause video 5 times slower.
Right/left arrow keys -- advance/go back one frame.
Page down/page up -- advance/go back 30 frames.
Home/end -- go to first/last frame of video.
See HELP VIDEOFIG for more options.
Joao Henriques (2021). Figure to play and analyze videos with custom plots on top (https://www.mathworks.com/matlabcentral/fileexchange/29544-figure-to-play-and-analyze-videos-with-custom-plots-on-top), MATLAB Central File Exchange. Retrieved .
Perfect! Thanks a lot!
how can i use this for my own plots. Lets say I have a for loop and in it my counter k goes through certain positions and and draw a plot for each position and I get the frames in a variable called M for example. in the for loop: ...............
M(k) = getframe(gcf)
Now I wanna use this function with the M with all the frames, how do I do that ?
Hi, I don't understand how to make this work. Could someone please explain? There's already a built in redraw.m file in matlab, am i supposed to modify that with the text in example 1? Also, how can I call my specific video so that I can play that video? where is the argument in which the user can input the path or name of the video they want to play? Thanks!
Very Helpful function!!!
One question: Is there a way to save the processed frames into an .avi file?
This is excellent!!
It's more than what I was looking for!
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!