psnr.m
上传用户:haoweisi88
上传日期:2010-02-03
资源大小:1950k
文件大小:1k
源码类别:

图形图象

开发平台:

Matlab

  1. %Name: Chris Shoemaker
  2. %Course: EER-280 - Digital Watermarking
  3. %Project:  Calculates the PSNR (Peak Signal to Noise Ratio)
  4. %            of images A and A', both of size MxN
  5. function [A] = psnr(image,image_prime,M,N)
  6.     % convert to doubles
  7.     image=double(image);
  8.     image_prime=double(image_prime);
  9.     % avoid divide by zero nastiness
  10.     if ((sum(sum(image-image_prime))) == 0)    
  11.         error('Input vectors must not be identical')
  12.     else
  13.         psnr_num=M*N*max(max(image.^2));                % calculate numerator
  14.         psnr_den=sum(sum((image-image_prime).^2));      % calculate denominator   
  15.         A=psnr_num/psnr_den;                            % calculate PSNR
  16.     end
  17. return