MATLAB Answers

convert images to video

110 views (last 30 days)
Angira Mahida
Angira Mahida on 27 Apr 2020
Edited: KSSV on 30 Apr 2020
hello there,
I need to make movie/video to show how the graph changes over time.
i have images named "hgate00.png" to "hgate79.png", each images have plot that keep changing slightly with each images.
i need to show how that changes through video of that 80 images.
also where should I kept that images and MATLAB file in folder so that they can work?
Thank you in advance.

Answers (2)

KSSV on 27 Apr 2020
imgFile = dir('*.png') ;
N = length(imgFiles) ;
% create the video writer with 1 fps
writerObj = VideoWriter('myVideo.avi');
writerObj.FrameRate = 10;
% open the video writer
% write the frames to the video
for i=1:N
img = imgFiles(i).name ;
I = imread(img) ;
imshow(I) ;
F = getframe(gcf) ;
writeVideo(writerObj, F);
% close the writer object
KSSV on 30 Apr 2020
Fix your desired size say to 512*512.....and you resize every image before you write into video using imresize.

Sign in to comment.

Christophe on 27 Apr 2020
Edited: Christophe on 27 Apr 2020
First you need to read your image. Use the imread function to do so.
Then, you can use the VideoWriter object to write videofiles.
Here is an untested program. Your png files must be in the current work directory. It will output the video in the same directory.
v = VideoWriter('newfile.avi','Uncompressed AVI');
for k = 0:79
A = imread(['hgate', num2str(k,'%02d'), '.png');
Please check the documentation for further explanation.
Angira Mahida
Angira Mahida on 30 Apr 2020
Its is not making video after hgate29.png files at all.
I tried creating another video for images 29 and onwards but no luck....

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!