Home > PR > psnr.m

psnr

PURPOSE ^

Takes two 8-bit IMAGES and computes peak-to-peak signal to noise ratio:

SYNOPSIS ^

function [gamma] = psnr(x,y)

DESCRIPTION ^

 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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [gamma] = psnr(x,y)
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 x = double(x);
0007 y = double(y);
0008 
0009 sx = size(x);
0010 sy = size(y);
0011 
0012 if sx == sy
0013    dd = x(:) - y(:);
0014    gg = (dd' * dd)/prod(sx);
0015    if (gg==0)
0016       gamma = Inf;
0017    else
0018       rr = 255^2./gg;
0019       gamma = 10 * log10(rr);
0020    end
0021 else
0022    fprintf ('\n Input image dimensions not consistent.');
0023    gamma = NaN;
0024 end

Generated on Wed 29-Nov-2006 16:19:19 by m2html © 2003