Comparing 2 frames from video

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;

 Accepted Answer

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 Comment

omg yes i forgot to add that, thank you so much sir!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!