Documentation

### This is machine translation

Mouseover text to see original. Click the button below to return to the English version of the page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

# psnr

Peak Signal-to-Noise Ratio (PSNR)

## Syntax

``peaksnr = psnr(A,ref)``
``peaksnr = psnr(A,ref,peakval)``
``````[peaksnr,snr] = psnr(___)``````

## Description

example

````peaksnr = psnr(A,ref)` calculates the peak signal-to-noise ratio for the image `A`, with the image `ref` as the reference. `A` and `ref` must be of the same size and class.```
````peaksnr = psnr(A,ref,peakval)` uses `peakval` as the peak signal value for calculating the peak signal-to-noise ratio for image `A`. ```
``````[peaksnr,snr] = psnr(___)``` returns the simple signal-to-noise ratio, `snr`, in addition to the peak signal-to-noise ratio.```

## Examples

collapse all

Read image and create a copy with added noise. The original image is the reference image.

```ref = imread('pout.tif'); A = imnoise(ref,'salt & pepper', 0.02);```

Calculate the PSNR.

```[peaksnr, snr] = psnr(A, ref); fprintf('\n The Peak-SNR value is %0.4f', peaksnr);```
``` The Peak-SNR value is 22.6437 ```
`fprintf('\n The SNR value is %0.4f \n', snr);`
``` The SNR value is 15.5524 ```

## Input Arguments

collapse all

Image to be analyzed, specified as an N-D numeric matrix.

Data Types: `single` | `double` | `int16` | `uint8` | `uint16`

Reference image, specified as an N-D numeric matrix.

Data Types: `single` | `double` | `int16` | `uint8` | `uint16`

Peak signal level, specified as a scalar of any numeric class. If not specified, the default value for `peakval` depends on the class of `A` and `ref`. If the images are of floating point types, `peakval` is `1`, assuming that the data is in the range `[0 1]`. If the images are of integer data types, `peakval` is the largest value allowed by the range of the class. For `uint8`, the default value is `255`. For `uint16` or `int16`, the default is `65535`.

Data Types: `single` | `double` | `int16` | `uint8` | `uint16`

## Output Arguments

collapse all

Peak signal-to-noise ratio in decibels, returned as a scalar of type `double`, except if `A` and `ref` are of class `single`, in which case `peaksnr` is of class `single`.

Data Types: `single` | `double`

Signal-to-noise ratio in decibels, returned as a scalar of type `double`, except if `A` and `ref` are of class `single`, in which case `peaksnr` is of class `single`.

Data Types: `single` | `double`

## Algorithms

The `psnr` function implements the following equation to calculate the Peak Signal-to-Noise Ratio (PSNR):

`$PSNR=10{\mathrm{log}}_{10}\left(peakva{l}^{2}/MSE\right)$`

where peakval is either specified by the user or taken from the range of the image datatype (e.g. for `uint8` image it is `255`). MSE is the mean square error, i.e. MSE between `A` and `ref`.