Creating movie from Images from a for loop
Afficher commentaires plus anciens
Hi there, I am currently producing images from a for loop, however I would like put these images into a movie or slideshow,however I am struggling to do this. Any help would be appreciated.
if true
% code
end
for i=t:Images
figure(i)
B=readimx(fullfile(filename,['B000',int2str(i),'.im7']));
C=B.Frames{1}.Components{1};
V = C.Planes;
I2=V{1,1};
Array3D(:,:,i-t+1)=I2;
K=imagesc(flipud(Array3D(:,:,i-t+1)));
set(gca,'YDir','normal');
end
Réponse acceptée
Plus de réponses (2)
Joseph Cheng
le 29 Mai 2015
Modifié(e) : Joseph Cheng
le 29 Mai 2015
you can follow the example of getframe() in the documentation located here:
example:
x=1:256;
[x y] = meshgrid(x,x);
figure(1)
vidfile = VideoWriter('testmovie.mp4','MPEG-4');
open(vidfile);
for ind = 1:256
z=sin(x*2*pi/ind)+cos(y*2*pi/ind);
imagesc(z),colormap(hot)
drawnow
F(ind) = getframe(gcf);
writeVideo(vidfile,F(ind));
end
close(vidfile)
Eswaramoorthy
le 3 Déc 2025
MATLAB's VideoWriter can be used to create a video file from images.
Here's an example from the VideoWriter documentation VideoWriter - Create object to write video files - MATLAB, which creates a video from images using a for-loop:
% Set up the axes and figure properties to generate frames for the video.
Z = peaks;
surf(Z);
axis tight manual;
set(gca,"NextPlot","replacechildren");
% Create a VideoWriter object for the output video file and open the object for writing.
v = VideoWriter("peaks.avi");
open(v);
% Generate a set of frames, get each frame from the figure, and then write each frame to the file.
for k = 1:20
surf(sin(2*pi*k/20)*Z,Z);
frame = getframe(gcf);
writeVideo(v,frame);
end
close(v);
Catégories
En savoir plus sur Audio and Video Data dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!