how to make a video out of sequenced images in order
2 views (last 30 days)
Show older comments
Srinidhi Bindiganavile Ramadas
on 18 Oct 2018
Commented: Srinidhi Bindiganavile Ramadas
on 18 Oct 2018
I have this code to make video file from a set of images. I have a folder with 1240 images numbered in order from 1 to 1240. But the video from the code does not start from the image1 but from the image numbered 1000 and goes till 1240 and starts from 1 to 999 again. I know that the reading of images from folder to matlab is going wrong somehow, but how to correct that?
What should I change in order for the video to start from image1 and go till the end. Appreciate the help.
if true
% % Make an avi movie from a collection of PNG images in a folder.
% Specify the folder.
myFolder = 'H:\My Documents\windowbanktests\tudMAT50M\images';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a directory listing.
filePattern = fullfile(myFolder, '*.PNG');
pngFiles = dir(filePattern);
% Open the video writer object.
writerObj = VideoWriter('YourAVI.avi');
writerObj.FrameRate = 10;
open(writerObj);
% Go through image by image writing it out to the AVI file.
for frameNumber = 1 : length(pngFiles)
% Construct the full filename.
baseFileName = pngFiles(frameNumber).name;
fullFileName = fullfile(myFolder, baseFileName);
% Display image name in the command window.
fprintf(1, 'Now reading %s\n', fullFileName);
% Display image in an axes control.
thisimage = imread(fullFileName);
imshow(thisimage); % Display image.
drawnow; % Force display to update immediately.
% Write this frame out to the AVI file.
writeVideo(writerObj, thisimage);
end
% Close down the video writer object to finish the file.
close(writerObj);
end
0 Comments
Accepted Answer
More Answers (1)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!