title: Did I correctly implement PSNR calculation code in Matlab?
body: <p>Is the following code a correct way of calculating PSNR for grayscale images in Matlab?</p>
  
  <pre><code>function p = psnr(x,y, vmax)
  
  if nargin&lt;3
      m1 = max( abs(x(:)) );
      m2 = max( abs(y(:)) );
      vmax = max(m1,m2);
  end
  
  d = mean( (x(:)-y(:)).^2 );
  
  p = 10*log10( vmax^2/d ); 
  </code></pre>
  
  <p>For 8-bit input, <code>vmax=255</code>.</p>