Calculating MSE (Mean Squared Error)

Brian Byrne picture Brian Byrne · Mar 1, 2012 · Viewed 9.7k times · Source

I'm not sure if this is the right place to ask this, but where can a find a step-by-step guide on how to compute the MSE of two images?

I know what the formula is but I have no idea how to put it into practice.

Answer

Paul R picture Paul R · Mar 1, 2012

In C you might do something like this:

int sum_sq = 0;
double mse;

for (i = 0; i < h; ++i)
{
    for (j = 0; j < w; ++j)
    {
        int p1 = image1[i][j];
        int p2 = image2[i][j];
        int err = p2 - p1;
        sum_sq += (err * err);
    }
}
mse = (double)sum_sq / (h * w);