I was trying to calculate similarity using MSE for the following images:
All the images are different but clearly the 1st & 3rd are the most similar. However, when I try to compute the MSE using numpy subtraction:
error = np.sum((imageA - imageB) ** 2)
error /= float(imageA.shape[0] * imageA.shape[1])
images A&B receive the smallest error (5.5 vs 7.7) which would be incorrect. However, if I convert the images to floats then do the subtraction
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
I get the right answer with A&C having the smallest error (1607 vs 24422). What would be the reason for this? The article this method is from mentions its to avoid "modulus operations wrapping around" but I also used cv2.subtract which I thought avoided that issue.