Takes two 8-bit IMAGES and computes peak-to-peak signal to noise ratio: gamma = 10 log (255^2/MSE) x and y must be the same dimension and may be 2D arrays or vectors.
0001 0002 % Takes two 8-bit IMAGES and computes peak-to-peak signal to noise ratio: 0003 % gamma = 10 log (255^2/MSE) 0004 % x and y must be the same dimension and may be 2D arrays or vectors. 0005 0006 function [gamma] = psnr(x,y) 0007 0008 x = double(x); 0009 y = double(y); 0010 0011 sx = size(x); 0012 sy = size(y); 0013 0014 if sx == sy 0015 dd = x(:) - y(:); 0016 gg = (dd' * dd)/prod(sx); 0017 if (gg==0) 0018 gamma = Inf; 0019 else 0020 rr = 255^2./gg; 0021 gamma = 10 * log10(rr); 0022 end 0023 else 0024 fprintf ('\n Input image dimensions not consistent.'); 0025 gamma = NaN; 0026 end