Figure to play and analyze videos with custom plots on top
编者注: This file was selected as MATLAB Central Pick of the Week
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:
http://blogs.mathworks.com/pick/2010/12/10/video-player-for-your-frame-based-processing/
EXAMPLE 1
Place this in a file called "redraw.m":
function redraw(frame)
imshow(['AT3_1m4_' num2str(frame, '%02.0f') '.tif'])
end
Then from a script or the command line, call:
videofig(10, @redraw);
redraw(1)
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.
EXAMPLE 2
Change the redraw function to visualize the contour of a single cell:
function redraw(frame)
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])
hold off
end
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 (2024). 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. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
- FPGA, ASIC, and SoC Development > Vision HDL Toolbox > Video Formats and Interfaces >
- Image Processing and Computer Vision > Vision HDL Toolbox > Video Formats and Interfaces >
- MATLAB > Graphics > 2-D and 3-D Plots > Animation > Movie >
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!