title: How does MATLAB calculate immse?
body: <p>How does Matlab calculate immse?  I want to find the mse between two images.  According to <a href="https://stackoverflow.com/questions/45987605/how-to-measure-he-similarity-between-two-2d-complex-fields-in-matlab/45996082#45996082">how to measure he similarity between two 2D complex fields in matlab?</a>, immse is the same as <code>MSE=mean((abs(Y(:))-abs(Y1(:))).^2)</code> for reference image Y1 and comparison image Y.  Likewise, I could calculate MSE as the summed square errors divided by the number of row*cols.  When I run on one of the demo images, these different approaches don't give the same answer as immse.  </p>
  
  <p>Here are two MSE approaches in the sample code below.  The image is from the Matlab immse demo and immse gives around an MSE=340.  The other two codes give around an MSE=2.5.  </p>
  
  <p>Note: The code is example code, I did not use the same function name twice in the same script.  And I understand if you want to complain about using size(image) but that is a detail.  I am more worried about the basic flaw in my understanding that is giving me orders of magnitude differences.  Thank you so much.     </p>
  
  <pre><code>n01 = imread('pout.tif');
  n02 = imnoise(n01,'salt &amp; pepper', 0.02);
  
  mse = mymse(n02,n01);
  mlmse = immse(n02,n01);
  
  function this = mymse(icomp, ibase)
      [X Y nchan] = size(ibase);
      diff = (icomp - ibase);
      this = sum(sum(diff.*diff))/(X*Y*nchan);
  end
  
  function this = mymse(icomp, ibase)
      this = mean ((abs(ibase(:)) - abs(icomp(:))).^2);
  end
  </code></pre>