MSE is known as Mean Squared Error. Basically, it is an optimization problem that is predominately used in image processing, signal processing, etc. Also, it is used as a loss function in machine learning and deep learning.
MSE is calculated by squaring the difference between the two identical points (error). It is the comparative measurement between two images or signals.
To calculate MSE, we must need two signals or images as I mentioned before that it is for performance comparison.
Calculate MSE for 1D Signal
Now we will see how to calculate the MSE value for a 1D signal. The formula –
Here, is the number of elements, is the original signal and is the newly generated signal or a completely different signal.
Explanation of 1D MSE Calculation:
Assuming we have a 1D signal –
and another one –
So, the MSE value would be –
x = [10,20,30,40] y = [10,19,32,43] summation = 0 #variable to store the summation of differences n = len(x) #finding total number of items in list for i in range (0,n): #looping through each element of the list difference = x[i] - y[i] #finding the difference between observed and predicted value squared_difference = difference**2 #taking square of the differene summation = summation + squared_difference #taking a sum of all the differences mse= summation/n #dividing summation by total values to obtain average print("Mean Square Error: ", mse)
Calculate MSE for 2D Signal
In the above example, we have seen MSE calculation for 1D signal. Suppose we need to calculate MSE for an image; in this situation we need to calculate MSE for 2D signal. The formula is –
Here, and are the number of rows and columns in the input image or the calculated 2D signal. Those two images must be the same dimensional.