You are currently viewing Matlab Code for PSNR  and MSE

Matlab Code for PSNR and MSE

Spread the love

PSNR is used to measure the quality of reconstruction of lossy and lossless compression  (e.g., for image compression). The signal in this case is the original data, and the noise is the error introduced by compression. When comparing compression codecs , PSNR is an approximation to human perception of reconstruction quality. Although a higher PSNR generally indicates that the reconstruction is of higher quality, in some cases it may not. PSNR is most easilydefined via the mean squared error.

psnr and mse
Here, MAXI is the maximum possible pixel value of the image. When the pixels are represented using 8 bits per sample, this is 255. More generally, when samples are represented using linear PCM with B bits per sample, MAXI is 2B−1. For color images with three RGB values per pixel, the definition of PSNR is the same except the MSE is the sum over all squared value differences divided by image size and by three.

 

Matlab Code for PSNR and MSE

InputImage=imread(‘Input.jpg’);
ReconstructedImage=imread(‘recon.jpg’);
n=size(InputImage);
M=n(1);
N=n(2);
MSE = sum(sum((InputImage-ReconstructedImage).^2))/(M*N);
PSNR = 10*log10(256*256/MSE);
fprintf('\nMSE: %7.2f ', MSE);
fprintf('\nPSNR: %9.7f dB', PSNR);