Creating movie from Images from a for loop
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (2)
Joseph Cheng
el 29 de Mayo de 2015
Editada: Joseph Cheng
el 29 de Mayo de 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
el 3 de Dic. de 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);
Categorías
Más información sobre Audio and Video Data en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!