Accelerating the pace of engineering and science

# measerr

Approximation quality metrics

## Syntax

[PSNR,MSE,MAXERR,L2RAT] = measerr(X,XAPP)
[...] = measerr(...,BPS)

## Description

[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.

## Input Arguments

 X X is a real-valued signal or image. XAPP XAPP is a real-valued signal or image approximation with a size equal to that of the input data, X. BPS BPS is the number of bits per sample in the data. Default: 8

## Output Arguments

 PSNR 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. MSE The mean square error (MSE) is the squared norm of the difference between the data and the approximation divided by the number of elements. MAXERR MAXERR is the maximum absolute squared deviation of the data, X, from the approximation, XAPP. L2RAT L2RAT is the ratio of the squared norm of the signal or image approximation, XAPP, to the input signal or image, X.

## Examples

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);
```

expand all

### Peak Signal to Noise Ratio (PSNR)

The following equation defines the PSNR:

$20{\mathrm{log}}_{10}\left(\frac{{2}^{B}-1}{\sqrt{MSE}}\right)$

where MSE represents the mean square error and B represents the bits per sample.

### Mean Square Error (MSE)

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:

$\frac{||X-Y|{|}^{2}}{N}$

## References

Huynh-Thu, Q.Scope of validity of PSNR in image/video quality assessment, Electronics Letters, 44, 2008, pp. 800–801.