フィルターのクリア

How to add image 'x' to even frames and one image 'y' to odd frames

2 ビュー (過去 30 日間)
Alber
Alber 2020 年 2 月 27 日
コメント済み: Alber 2020 年 3 月 9 日
Hello,
I have a video that we will call 'x' and some images that we will call 'output_cross_alfa' and 'output_cross_Nalfa'.
My goal is to make the sum of 'x' with 'output_cross_alfa' in the even frames, and in the odd frames the sum of 'x' is done with 'output_cross_Nalfa'. The final video should be:
frame1 = frame1 + output_cross_Nalfa;
frame2 = frame2 + output_cross_alfa;
frame3 = frame3 + output_cross_Nalfa;
frame4 = frame4 + output_cross_alfa;
......
To do this I used this code:
for ii = 1: 2: length (imageNames)
for kk = 2: 2: length (imageNames)
img1 = im2single (imread (fullfile (workingDir, 'images', imageNames {ii})));
image_2 = im2single (img1 + output_cross_alfa);
img2 = im2single (imread (fullfile (workingDir, 'images', imageNames {kk})));
image_1 = im2single (img2 + output_cross_Nalfa);
output = uint8 (image_par + image_par);
writeVideo (outputVideo, output);
end
end
But I only get screenshots in black and gray when representing it.
To represent it I use this:
shuttleAvi = VideoReader (fullfile (workingDir, 'shuttle_out.avi'));
ii = 1;
while hasFrame (shuttleAvi)
mov (ii) = (im2frame (readFrame (shuttleAvi)));
ii = ii + 1;
end
figure, imshow (mov (1) .cdata, 'Border', 'tight');
movie (mov, 1, shuttleAvi.FrameRate);
And I have no idea what the failure may be.

採用された回答

Prabhan Purwar
Prabhan Purwar 2020 年 3 月 5 日
Hi,
According to your description there doesn't seem any need for nested loops. Try making use of the following code:
outputVideo= VideoWriter('newfile.avi');
open(outputVideo);
for ii = 1: 2: length (imageNames)
kk=ii+1;
img1 = im2single (imread (fullfile (workingDir, 'images', imageNames {ii})));
image_2 = im2single (img1 + output_cross_alfa);
img2 = im2single (imread (fullfile (workingDir, 'images', imageNames {kk})));
image_1 = im2single (img2 + output_cross_Nalfa);
output = image_1;
writeVideo (outputVideo, output);
output = image_2;
writeVideo (outputVideo, output);
end
close(outputVideo);
Hope it helps.
  1 件のコメント
Alber
Alber 2020 年 3 月 9 日
Thank you so much. Finally I solved my problem using one conditional like : if (rem(i,2)== 0)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by