필터 지우기
필터 지우기

convert images to video

조회 수: 183 (최근 30일)
Angu
Angu 2020년 4월 27일
댓글: Jaime Abad Arredondo 2023년 12월 13일
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.

답변 (3개)

yanqi liu
yanqi liu 2022년 1월 5일
clc; clear all; close all;
selpath = uigetdir(fullfile(pwd),'Choose image folder');
if isequal(selpath, 0)
return;
end
imgFilePath = selpath;
filename_out = fullfile(pwd, 'out.avi');
% "hgate00.png" to "hgate79.png"
startnum = 0;
endnum = 79;
% create video file
writerObj = VideoWriter(filename_out);
writerObj.FrameRate = 24;
open(writerObj);
h = waitbar(0, '', 'Name', 'Write Video File...');
steps = endnum - startnum;
for num = startnum : endnum
file = sprintf('hgate%02d.png', num);
file = fullfile(imgFilePath, file);
frame = imread(file);
frame = im2frame(frame);
writeVideo(writerObj,frame);
pause(0.01);
step = num - startnum;
waitbar(step/steps, h, sprintf('Process:%d%%', round(step/steps*100)));
end
close(writerObj);
close(h);

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);
  댓글 수: 8
Anu
Anu 2022년 1월 4일
Thanks @KSSV. There is a typo in the first line of your code. It should be: imgFiles = dir('*.png')
Jaime Abad Arredondo
Jaime Abad Arredondo 2023년 12월 13일
I want to add something that might save some time for someone:
If you use imshow and the images are larger than your screen size, then imshow will downscale the image to fit in your screen. Therefore all the parameters of writevideo will result in (in some cases) very low video quality.
A workaround to this is to use:
F=im2frame(I);
Instead of imshow and getframe, just like @yanqi liu used in their solution.

댓글을 달려면 로그인하십시오.


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
Angu
Angu 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...
Angu
Angu 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....

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by