MATLAB Answers

Comparing 2 frames from video

1 ビュー (過去 30 日間)
ArianaLaverly
ArianaLaverly 2021 年 6 月 16 日
コメント済み: ArianaLaverly 2021 年 6 月 17 日
I want to compare first video frames from original video and edited video, when i'm comparing r and r2 it always show error :
Error in psnr (line 3)
original_img=double(original_img);
Output argument "MSE" (and maybe others) not assigned during call to "psnr".
Error in videoStego (line 186)
[P,MSE]=psnr(r,r2);
But if i'm comparing other variables like r and b2, g and r2, etc it just run smoothly. Here is my code:
ori = VideoReader('Ori.avi');
frame = read(ori,1);
img=frame(:,:,:,1);
r=img(:,:,1);
g=img(:,:,2);
b=img(:,:,3);
edited = VideoReader('Edited.avi');
frame2 = read(v,1);
img2=frame2(:,:,:,1);
r2=img2(:,:,1);
g2=img2(:,:,2);
b2=img2(:,:,3);
[P,MSE]=psnr(r,r2);
And here is the psnr code:
function [P,MSE]=psnr(original_img,stego_img)
original_img=double(original_img);
stego_img=double(stego_img);
if (original_img==stego_img)
PSNR=100;
else
m = size(original_img,1);
n = size(stego_img,2);
d = 0 ;
for i = 1:m-1
for j = 1:n-1
d = d + (original_img(i,j) - stego_img(i,j)).^2 ;
end
end
MSE=d/(m*n);
MAX = max( abs(original_img(:)) );
PSNR= 10*log10(MAX^2/MSE);
end
P=PSNR;

採用された回答

Stephan
Stephan 2021 年 6 月 17 日
Try:
function [P,MSE]=Untitled(original_img,stego_img)
original_img=double(original_img);
stego_img=double(stego_img);
if (original_img==stego_img)
PSNR=100;
MSE=0; % Added this line
else
m = size(original_img,1);
n = size(stego_img,2);
d = 0 ;
for i = 1:m-1
for j = 1:n-1
d = d + (original_img(i,j) - stego_img(i,j)).^2 ;
end
end
MSE=d/(m*n);
MAX = max( abs(original_img(:)) );
PSNR= 10*log10(MAX^2/MSE);
end
P=PSNR;
end
  1 件のコメント
ArianaLaverly
ArianaLaverly 2021 年 6 月 17 日
omg yes i forgot to add that, thank you so much sir!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by