If you have two images that can be arbitrarily scaled but you want to compare them in a mean square error sense, then I have a package for you.

The least mean square error (LMSE) package contains two subroutines. LMSE computes the minimum mean square error (MSE) possible if one image is allowed to be linearly scaled in intensity. Given a linear scaling of an image (slope and intercept), a pseudoinverse is used to solve for the two scalar parameters that minimize in a least-squares sense the difference between the image in question and a fixed reference image:

A = ones(numel(target_image),2);
A(:,1) = target_image;
coeffs = A \ reference_image;
err = norm(coeffs(1)*target_image + coeffs(2) - reference_image) / ...
    numel(target_image);

Here both images are represented as column vectors.

LMSEDIFF computes the difference image after the target image is scaled according to the scaling that minimizes the MSE. This is a better way to compare images if the absolute magnitude of the intensity has no meaning.

LMSE Difference between two Shepp-Logan Phantoms before (left) and after (right) LMSE scaling. You can see that the true, scale-free differences in the images are much smaller than a naive differencing would leave you to believe.

The LMSE makes sense if all you care about are the features in the image, not the absolute pixel values. This is often the case in diagnostic radiology, for example.