www.pudn.com > watermark.rar > psnr.m, change:2008-05-12,size:572b


function dPSNR = psnr(cover_object,watermarked_image)  
 
if (size(cover_object,1) ~= size(watermarked_image,1)) or (size(cover_object,2) ~= size(watermarked_image,2))  
  error('cover_object <> watermarked_image');  
  dPSNR = 0;  
  return ;  
end  
cover_object=double(cover_object);  
ImageB=double(watermarked_image);  
M = size(cover_object,1);  
N = size(cover_object,2);  
   
d = 0 ;  
for i = 1:M  
  for j = 1:N  
    d = d + (cover_object(i,j) - watermarked_image(i,j)).^2 ;  
  end  
end  
 
dPSNR = 10*log10((M*N*max(max(cover_object.^2)))/d) ;  
 
return