Comparing 2 frames from video

조회 수: 4 (최근 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