make video to combine two png series from different file folder

Hello,
i would like to combine two png series from different file folder and make video
for example: below I attached screenshot of the png folders of pressure and velocity. I would like to make a video to combine pressure and velocity.
thank you in advance
Yijun

 Accepted Answer

How about the following solution?
s = dir('*.png');
v = VideoWriter('output.avi');
open(v);
for kk = 1:numel(s)
filePath = fullfile(s(kk).folder,s(kk).name);
I = imread(filePath);
writeVideo(v,I);
end
close(v);

6 Comments

thank you for your answer. But I would like to combine velocity and pressure in one video.like left part of the video is the velocity png and right part of the video is pressure png. Is it possible with matlab?
Combine the images side by side like this
pressureImage = imread(filePathP);
velocityImage = imread(filePathV);
bothImages = [pressureImage, velocityImage];
writeVideo(v, bothImages);
Hi Image Analyst-san,
Thank you for your comment!
Thank you for your help. I have implemented as following. But I got an error, due to different size of image. (size of F_IR: 440X1075X3 unit8 | size of F_OR 439X1073X3). I am sure I have both the same number of element of pngs in both folders. Could you please tell me how I change the size of my image? Thank you
cd F_xy_IR
FIR = dir('*.png');
cd ..
cd F_xy_OR
FOR = dir('*.png');
v = VideoWriter('output.avi');
open(v);
for kk = 1:numel(s)
filePath_IR = fullfile(FIR(kk).folder,FIR(kk).name);
filePath_OR = fullfile(FOR(kk).folder,FOR(kk).name);
%I = imread(filePath);
%writeVideo(v,I);
F_IR = imread(filePath_IR);
F_OR = imread(filePath_OR);
bothImages = [F_IR, F_OR];
writeVideo(v, bothImages);
end
close(v);
>> video_F_IROR
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in video_F_IROR (line 17)
bothImages = [F_IR, F_OR];
You can simply adjust the image size just before combining them, like:
...
F_IR = imread(filePath_IR);
F_OR = imread(filePath_OR);
F_OR = imresize(F_OR,size(F_IR,[1,2])); % <- Added this line
bothImages = [F_IR, F_OR];
...
thank you for you help. It works
best regards
Yijun

Sign in to comment.

More Answers (0)

Tags

Asked:

on 21 Apr 2020

Commented:

on 26 Apr 2020

Community Treasure Hunt

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

Start Hunting!