Creating movie from Images from a for loop
226 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Oliver Woodford
2015-5-29
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 个评论
Marcus Lehr
2018-8-24
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
更多回答(1 个)
Joseph Cheng
2015-5-29
编辑:Joseph Cheng
2015-5-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!