Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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

collapse all

Approximate an RGB image and calculate approximation quality metrics.

Load an image.

X = imread('africasculpt.jpg');

Define the image approximation.

Xapp = X;
Xapp(X<=100) = 1;

Calculate the approximation quality metrics.

[psnr,mse,maxerr,L2rat] = measerr(X,Xapp)
psnr =

   17.5287


mse =

   1.1487e+03


maxerr =

    99


L2rat =

    0.9398

Display the image and its approximation.

figure
subplot(1,2,1)
image(X)
title('Original Image')
subplot(1,2,2)
image(Xapp)
title('Approximation')

Approximate an image and calculate approximation quality metrics.

Load an image.

load woman;

Define the image approximation.

Xapp = X;
Xapp(X<=50) = 1;

Calculate approximation quality metrics.

[psnr,mse,maxerr,L2rat] = measerr(X,Xapp)
psnr = 26.5884
mse = 142.6411
maxerr = 47
L2rat = 0.9910

Create a plot.

figure; colormap(map);
subplot(1,2,1); image(X); 
subplot(1,2,2); image(Xapp);

More About

collapse all

Peak Signal to Noise Ratio (PSNR)

The following equation defines the PSNR:

20log10(2B1MSE)

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:

||XY||2N

References

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

Introduced in R2010b

Was this topic helpful?