Peak signal-to-noise ratio (PSNR)
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
A— Image to be analyzed
Image to be analyzed, specified as a numeric array of any dimension.
ref— Reference image
Reference image, specified as a numeric array of the same size and data type as image
peakval— Peak signal level
If the images are of data type
assumes that image data is in the range [0, 1]. The default
If the images are of integer data types, then the default
peakval is the largest value
allowed by the range of the class. For
data, the default value of
int16, the default is
psnr function implements this equation to calculate PSNR:
Usage notes and limitations:
psnr supports the generation of C
code (requires MATLAB®
Coder™). For more information, see Code Generation for Image Processing.