Accelerating the pace of engineering and science

# psnr

Peak Signal-to-Noise Ratio (PSNR)

## Syntax

• peaksnr = psnr(A,ref) example
• 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

expand all

### Calculate PSNR for Noisy Image Given Original Image as Reference

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);
fprintf('\n The SNR value is %0.4f \n', snr);
```
```The Peak-SNR value is 22.8810
The SNR value is 15.7897 ```

## Input Arguments

expand all

### A — Image to be analyzedN-D numeric matrix

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

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

### ref — Reference imageN-D numeric matrix

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

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

### peakval — Peak signal levelscalar of any numeric class

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

expand all

### peaksnr — Peak signal-to-noise ratioscalar

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

### snr — Signal-to-noise ratioscalar

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

expand all

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