I am trying to calculate the MSE between two images.
In Matlab the
immsefunction contains an unexpected formula which is(norm(x(:)-y(:),2).^2)/numel(x).My teacher instead is using
mean((x(:)-y(:)).^2).
I saw that the results of the method with the mean is more or less half of the other's method.
According to Wikipedia, my teacher's version seems to be the correct one.
What's the right version to use? Why are there these differences?
They are different forms of computing the same thing, and they do give the same answer. We can test this is the same using an example
This is why...
According to the norm documentation,
norm(v,2)is equivalent tonorm(v)or the Euclidean norm, defined as the square root of the sum of squaresYour own Wikipedia link defines MSE as
We can combine these (using consistent lettering for
n=Nank=ifrom the two sources)Definition of
norm(v,2)and this expression squared:Let:
And substitute into the MSE equation:
Which is the calculation done within
immse:(norm(x(:)-y(:),2).^2)/numel(x)So the definitions given by Wikipedia and MATLAB's
immseare the same. The introductory sentence for the Wiki article even mentions the normThis is equivalent to your teacher's definition. They are using
meanto perform the summation overi=1..nand division byn, and computing the square of the delta which is the same as the squared Euclidean norm.