For grayscale images, I used the Mean Square Error as an indicator of how two different images used to be. Just insert the corresponding pixels from each image into the formula.
Not only can this tell you if they are exactly the same, but it can also tell you how different the two images are, although quite rudely.
https://en.wikipedia.org/wiki/Mean_squared_error
EDIT:
Note. This is C # code, not Java (apologies, but what I wrote at the beginning), however it should be easily portable.
//Calculates the MSE between two images private double MSE(Bitmap original, Bitmap enhanced) { Size imgSize = original.Size; double total = 0; for (int y = 0; y < imgSize.Height; y++) { for (int x = 0; x < imgSize.Width; x++) { total += System.Math.Pow(original.GetPixel(x, y).R - enhanced.GetPixel(x, y).R, 2); } } return (total / (imgSize.Width * imgSize.Height)); }
source share