Creating movie from Images from a for loop
201 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Robert Roy
le 29 Mai 2015
Commenté : Marcus Lehr
le 24 Août 2018
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
0 commentaires
Réponse acceptée
Oliver Woodford
le 29 Mai 2015
Produce your images programmatically, rather than by exporting a figure, if you can, as it will be much faster. SC (on the FEX) is good for this. Editing Joseph Cheng's code, you would do the following:
[y, x] = ndgrid(1:256);
vidfile = VideoWriter('testmovie.mp4','MPEG-4');
open(vidfile);
for ind = 1:256
z = sin(x*2*pi/ind)+cos(y*2*pi/ind);
im = sc(z, 'hot');
writeVideo(vidfile, im);
end
close(vidfile)
1 commentaire
Marcus Lehr
le 24 Août 2018
Hi Oliver,
I'm trying to use this method however the video file I'm trying to make is of contour plots. writeVideo() gives me the following error:
IMG must be of one of the following classes: double, single, uint8
I've tried converting the data with C2xyz and saving it with SC but it hasn't helped. sc() returns
Conversion to double from cell is not possible.
Any idea how I can convert data created by contour() into a normal image file that I can write? The only workaround I've so far is saving each plot with saveas(), then converting the resulting image files to a stack with imagej. Any better solutions would be appreciated.
Thanks
Plus de réponses (1)
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)
0 commentaires
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!