Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to get the (MSE) mean error squared for 2 images?

The MSE is the average of the channel error squared.

What does that mean in comparing two same size images?

like image 438
samwise Avatar asked Nov 28 '13 17:11

samwise


4 Answers

For two pictures A, B you take the square of the difference between every pixel in A and the corresponding pixel in B, sum that up and divide it by the number of pixels.

Pseudo code:

sum = 0.0
for(x = 0; x < width;++x){
   for(y = 0; y < height; ++y){
      difference = (A[x,y] - B[x,y])
      sum = sum + difference*difference
   }
}
mse = sum /(width*height)
printf("The mean square error is %f\n",mse) 
like image 67
josefx Avatar answered Nov 15 '22 09:11

josefx


Conceptually, it would be:

1) Start with red channel
2) Compute the difference between each pixel's gray level value in the two image's red channels pixel-by-pixel (redA(0,0)-redB(0,0) etc for all pixel locations.
3) Square the differences of every one of those pixels (redA(0,0)-redB(0,0)^2
4) Compute the sum of the squared difference for all pixels in the red channel
5) Repeat above for the green and blue channels
6) Add the 3 sums together and divide by 3, i.e, (redsum+greensum+bluesum)/3
7) Divide by the area of the image (Width*Height) to form the mean or average, i.e., (redsum+greensum+bluesum)/(3*Width*Height) = MSE


Note that the E in error is synonymous with difference. So it could be called the Mean Squared Difference. Also mean is the same as average. So it could also be called the Average Squared Difference.

like image 35
fmw42 Avatar answered Nov 15 '22 11:11

fmw42


You can have a look at following article: http://en.wikipedia.org/wiki/Mean_squared_error#Definition_and_basic_properties. There "Yi" represents the true values and "hat_Yi" represents the values with which we want to compare the true values.

So, in your case you can consider one image as the reference image and the second image as the image whose pixel values you would like to compare with the first one....and you do so by calculating the MSE which tells you "how different/similar is the second image to the first one"

like image 38
skm Avatar answered Nov 15 '22 11:11

skm


Check out wikipedia for MSE, it's a measure of the difference between each pixel value. Here's a sample implementation

def MSE(img1, img2):
        squared_diff = (img1 -img2) ** 2
        summed = np.sum(squared_diff)
        num_pix = img1.shape[0] * img1.shape[1] #img1 and 2 should have same shape
        err = summed / num_pix
        return err
like image 43
James L. Avatar answered Nov 15 '22 11:11

James L.