Clear Filters
Clear Filters

How do I create a video from an image being rotated?

13 views (last 30 days)
I am trying to create a video by combining an image that is being rotated. The code gives me an .avi file, but the image is not rotating.
FPS=24;
time=10;
theta=1;
degPerFrame=10;
movie=VideoWriter('spinspokes.avi'); %create new video file
open(movie);
for i=1:FPS*time
B=imread('spokes.tif'); %open image file
writeVideo(movie,B);
pause(0.01)
theta=theta+degPerFrame;
B=imrotate(B,theta,'bilinear','crop'); %rotate image
end
close(movie);
implay('spinspokes.avi')

Accepted Answer

Dave B
Dave B on 1 Nov 2021
You're reading in the image, then writing the video frame, then rotating the image. I think you intended to rotate the video before writing the video:
for i=1:FPS*time
B=imread('spokes.tif'); %open image file
pause(0.01)
theta=theta+degPerFrame;
B=imrotate(B,theta,'bilinear','crop'); %rotate image
writeVideo(movie,B);
end
Better still, just read in the video once:
B=imread('spokes.tif'); %open image file
for i=1:FPS*time
theta = theta + degPerFrame;
B_rotate = imrotate(B, theta, 'bilinear', 'crop'); %rotate image
writeVideo(movie, B_rotate);
end

More Answers (0)

Tags

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!