/** * Computes the mean squared error (MSE) between the two images. * * @param imgA first image. Not modified. * @param imgB second image. Not modified. * @return error between the two images. */ public static double computeMeanSquaredError(ImageInt8 imgA, ImageInt8 imgB) { final int h = imgA.getHeight(); final int w = imgA.getWidth(); double total = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { double difference = imgA.get(x, y) - imgB.get(x, y); total += difference * difference; } } return total / (w * h); }