Creating movie from Images from a for loop

230 Ansichten (letzte 30 Tage)
Robert Roy
Robert Roy am 29 Mai 2015
Kommentiert: Marcus Lehr am 24 Aug. 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

Akzeptierte Antwort

Oliver Woodford
Oliver Woodford am 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 Kommentar
Marcus Lehr
Marcus Lehr am 24 Aug. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Joseph Cheng
Joseph Cheng am 29 Mai 2015
Bearbeitet: Joseph Cheng am 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)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by