Approximation quality metrics
[...] = measerr(...,BPS)
[PSNR,MSE,MAXERR,L2RAT] = measerr(X,XAPP) returns the peak signal-to-noise ratio, PSNR, mean square error, MSE, maximum squared error, MAXERR, and ratio of squared norms, L2RAT, for an input signal or image, X, and its approximation, XAPP.
[...] = measerr(...,BPS) uses the bits per sample, BPS, to determine the peak signal-to-noise ratio.
X is a real-valued signal or image.
XAPP is a real-valued signal or image approximation with a size equal to that of the input data, X.
BPS is the number of bits per sample in the data.
PSNR is the peak signal-to-noise ratio in decibels (dB). The PSNR is only meaningful for data encoded in terms of bits per sample, or bits per pixel. For example, an image with 8 bits per pixel contains integers from 0 to 255.
The mean square error (MSE) is the squared norm of the difference between the data and the approximation divided by the number of elements.
Approximate an image and calculate approximation quality metrics.
load woman; Xapp = X; Xapp(X<=50) = 1; [psnr,mse,maxerr,L2rat] = measerr(X,Xapp); figure; colormap(map); subplot(1,2,1); image(X); subplot(1,2,2); image(Xapp);
Measure approximation quality in an RGB image.
X = imread('africasculpt.jpg'); Xapp = X; Xapp(X<=100) = 1; [psnr,mse,maxerr,L2rat] = measerr (X,Xapp) figure; subplot(1,2,1); image(X); subplot(1,2,2); image(Xapp);
The following equation defines the PSNR:
where MSE represents the mean square error and B represents the bits per sample.
The mean square error between a signal or image, X, and an approximation, Y, is the squared norm of the difference divided by the number of elements in the signal or image:
Huynh-Thu, Q.Scope of validity of PSNR in image/video quality assessment, Electronics Letters, 44, 2008, pp. 800–801.