Documentation

# 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.```
````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 a numeric array of any dimension.

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

Reference image, specified as a numeric array of the same size and data type as image `A`.

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

Peak signal level, specified as a nonnegative number. If not specified, the default value for `peakval` depends on the class of `A` and `ref`.

• If the images are of data type `double` or `single`, then `psnr` assumes that image data is in the range [0, 1] and the default value of `peakval` is `1`.

• If the images are of integer data types, then the default value of `peakval` is the largest value allowed by the range of the class. For `uint8` data, the default value of `peakval` is `255`. For `uint16` or `int16`, the default is `65535`.

## 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 numeric scalar of type `double`, except if `A` and `ref` are of class `single`, in which case `peaksnr` is of type `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`.