# finding of mse and psnr

28 views (last 30 days)
Jitesh Bhanushali on 11 Apr 2014
Edited: Image Analyst on 11 Apr 2014
sir i have attached a code . i want to find mse and psnr of the original image(I) and reconstruted image (y). i have used following code but it gives me error. how to find this parameters??
D = abs(I-y).^2; MSE = sum(D(:))/numel(I)
PSNR=10*log10(255*255/MSE)
Jitesh Bhanushali on 11 Apr 2014
this is the code

Image Analyst on 11 Apr 2014
Edited: Image Analyst on 11 Apr 2014
Did you cast y and (the badly named) I do double before you did the subtraction? Otherwise negative values will get clipped to zero. For example (7-9).^2 = 0^2 = 0, not 2^2 = 4 like you probably expect. See my attached demo, which you can use if you don't have the new built-in psnr() function that Spandan told us about. Here's the key lines in a snippet:
squaredErrorImage = (double(grayImage) - double(noisyImage)) .^ 2;
% Sum the Squared Image and divide by the number of elements
% to get the Mean Squared Error. It will be a scalar (a single number).
mse = sum(sum(squaredErrorImage)) / (rows * columns);
% Calculate PSNR (Peak Signal to Noise Ratio) from the MSE according to the formula.
PSNR = 10 * log10( 256^2 / mse);

Spandan Tiwari on 11 Apr 2014
There's a function named psnr() in Image Processing Toolbox in R2014a for computing PSNR. MSE is also computed on the way to computing PSNR.
BTW, what error do you get with your code? What parameters do you want to find?

### Categories

Find more on Template Matching in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by