MATLAB Answers

convert images to video

63 ビュー (過去 30 日間)
Angira Mahida
Angira Mahida 2020 年 4 月 27 日
編集済み: KSSV 2020 年 4 月 30 日
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.

  0 件のコメント

サインインしてコメントする。

回答 (2 件)

KSSV
KSSV 2020 年 4 月 27 日
imgFile = dir('*.png') ;
N = length(imgFiles) ;
% create the video writer with 1 fps
writerObj = VideoWriter('myVideo.avi');
writerObj.FrameRate = 10;
% open the video writer
open(writerObj);
% 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);
end
% close the writer object
close(writerObj);

  6 件のコメント

表示 3 件の古いコメント
KSSV
KSSV 2020 年 4 月 30 日
Why NaN? You need to fix a size first and resize every image into this size.
Angira Mahida
Angira Mahida 2020 年 4 月 30 日
how??
KSSV
KSSV 2020 年 4 月 30 日
Fix your desired size say to 512*512.....and you resize every image before you write into video using imresize.

サインインしてコメントする。


Christophe
Christophe 2020 年 4 月 27 日
編集済み: Christophe 2020 年 4 月 27 日
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');
open(v)
for k = 0:79
A = imread(['hgate', num2str(k,'%02d'), '.png');
writeVideo(v,A)
end
close(v)
Please check the documentation for further explanation.

  5 件のコメント

表示 2 件の古いコメント
Angira Mahida
Angira Mahida 2020 年 4 月 30 日
one more problem...
few images are not there,
such as hgate71.png,hgate75.png.
how shoud I ignore the missing images?
Angira Mahida
Angira Mahida 2020 年 4 月 30 日
the script is working for 01 to 70 images, but the video has just 01 to 29 images in a second and then just blank... how to solve that?? also the images are moving way to fast...
Angira Mahida
Angira Mahida 2020 年 4 月 30 日
Its is not making video after hgate29.png files at all.
I tried creating another video for images 29 and onwards but no luck....

サインインしてコメントする。

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by