# Documentation

### This is machine translation

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

# PSNR

Compute peak signal-to-noise ratio (PSNR) between images

## Library

Statistics

`visionstatistics`

## Description

The PSNR block computes the peak signal-to-noise ratio, in decibels, between two images. This ratio is often used as a quality measurement between the original and a compressed image. The higher the PSNR, the better the quality of the compressed, or reconstructed image.

The Mean Square Error (MSE) and the Peak Signal to Noise Ratio (PSNR) are the two error metrics used to compare image compression quality. The MSE represents the cumulative squared error between the compressed and the original image, whereas PSNR represents a measure of the peak error. The lower the value of MSE, the lower the error.

To compute the PSNR, the block first calculates the mean-squared error using the following equation:

`$MSE=\frac{\sum _{M,N}{\left[{I}_{1}\left(m,n\right)-{I}_{2}\left(m,n\right)\right]}^{2}}{M*N}$`

In the previous equation, M and N are the number of rows and columns in the input images, respectively. Then the block computes the PSNR using the following equation:

`$PSNR=10{\mathrm{log}}_{10}\left(\frac{{R}^{2}}{MSE}\right)$`

In the previous equation, R is the maximum fluctuation in the input image data type. For example, if the input image has a double-precision floating-point data type, then R is 1. If it has an 8-bit unsigned integer data type, R is 255, etc.

### Recommendation for Computing PSNR for Color Images

Different approaches exist for computing the PSNR of a color image. Because the human eye is most sensitive to luma information, compute the PSNR for color images by converting the image to a color space that separates the intensity (luma) channel, such as YCbCr. The Y (luma), in YCbCr represents a weighted average of R, G, and B. G is given the most weight, again because the human eye perceives it most easily. With this consideration, compute the PSNR only on the luma channel.

### Ports

PortOutputSupported Data TypesComplex Values Supported

I1

Scalar, vector, or matrix of intensity values

• Double-precision floating point

• Single-precision floating point

• Fixed point

• 8-, 16-, and 32-bit signed integer

• 8-, 16-, and 32-bit unsigned integer

No

I2

Scalar, vector, or matrix of intensity values

Same as I1 port

No

Output

Scalar value that represents the PSNR

• Double-precision floating point

For fixed-point or integer input, the block output is double-precision floating point. Otherwise, the block input and output are the same data type.

No