making video from large number of images

조회 수: 7 (최근 30일)
talayeh ghodsi
talayeh ghodsi 2020년 12월 29일
답변: KALYAN ACHARJYA 2020년 12월 29일
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