making video from large number of images

2 次查看(过去 30 天)
hi every body.
I have 368 images in a folder. i nead to make a video from them. i hav find a mathlab code by search, but i have an error in line 19, (frame = im2frame(pic{u})). and also i dont know how can i fix "secsPerImage" in line 13 for all 368 images equal to 2 seconds per image.
could anyone help me please?
surf_read_dir='E:\phd\shadi gholipoor\shadi gholipoor jpg\Series_10448_70.0%\';
files=dir('E:\phd\shadi gholipoor\shadi gholipoor jpg\Series_10448_70.0%\*.jpg');
for im=1:size(files)
fdir = strcat(surf_read_dir , files(im).name);
slice_im = load(fdir);
pic = imread(fdir);
end
writerObj = VideoWriter('myVideo.avi');
writerObj.FrameRate = 1;
% set the seconds per image
% secsPerImage = [5 10 15];
% open the video writer
open(writerObj);
% write the frames to the video
for u=1:length(pic)
% convert the image to a frame
frame = im2frame(pic{u});
for v=1:secsPerImage(u)
writeVideo(writerObj, frame);
end
end
% close the writer object
close(writerObj);

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020-12-29
One error I have need notiching that, at the initial loop, you consider "pic" as single variable. However, in the 2nd loop, it is called as as cell array, it might be-
for im=1:size(files)
.....
pic{im}= imread(fdir);
end
A lot of similar question answers are available in MATLAB Answers (call sequence of images), and the later part converts them into frames using the im2frame function.

Community Treasure Hunt

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

Start Hunting!

Translated by