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

Approximate a grayscale image and calculate approximation quality metrics.

Create a 256-by-256 grayscale image with intensities between $$0$$ and $${2}^{16}-1$$.

val = 0:2^16-1;
X = reshape(val,256,256);

There are 16 bits per sample. Define the image approximation by setting equal to 1 all grayscale values less than or equal to 1000. Display the image and its approximation.

Input signal or image, specified as a real-valued array.

XAPP — Approximation of signal or image real-valued array

Approximation of signal or image X, specified as a real-valued
array. XAPP is the same size as X.

BPS — Bits per sample 8 (default) | positive integer

Bits per sample of the input data, specified as a positive integer. The default
value is 8, so the maximum possible pixel value of an image (MAXI) is
255. More generally, when samples are represented using linear Pulse Code Modulation
with B bits per sample, MAXI is 2^{B}−1.

PSNR — Peak signal-to-noise ratio positive real number

Peak signal-to-noise ratio (PSNR) in decibels, returned as a positive real number.
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 — Mean square error positive real number

Mean square error, returned as a positive real number. MSE is
the squared norm of the difference between X and
XAPP divided by the number of elements.

MAXERR — Maximum absolute squared deviation positive real number

Maximum absolute squared deviation of the data X from the
approximation XAPP, returned as a positive real number.

L2RAT — Energy ratio positive real number

Energy ratio between the approximation XAPP and input data
X, returned as a positive real number. L2RAT
is the ratio of the squared norm of XAPP to
X.

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

Mean Square Error

The mean square error (MSE) between a signal or image,
X, and an approximation, Y, is

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

where N is the number of elements in the
signal.

References

[1] Huynh-Thu, Q. and M. Ghanbari.
"Scope of Validity of PSNR in Image/Video Quality Assessment." Electronics
Letters. Vol. 44, Issue 13, 2008, pp. 800–801.

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.