MATLAB Answers

make video to combine two png series from different file folder

1 view (last 30 days)
yijun guo
yijun guo on 21 Apr 2020
Commented: yijun guo on 26 Apr 2020
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

  0 Comments

Sign in to comment.

Accepted Answer

Akira Agata
Akira Agata on 22 Apr 2020
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

Show 3 older comments
yijun guo
yijun guo on 24 Apr 2020
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];
Akira Agata
Akira Agata on 25 Apr 2020
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];
...

Sign in to comment.

More Answers (0)

Tags