What is peak signal-to-noise ratio in image processing

Digital image processing deals with the reconstruction and enhancement of images and plays a crucial role in various fields, including photography, medical imaging, and computer vision. However, various methods to assess image quality also exist in the image fidelity criteria. One of these methods is the calculation of the peak signal-to-noise ratio.

Understanding peak signal-to-noise ratio (PSNR)

Peak signal-to-noise ratio is a widely used metric that measures the quality of a processed image by comparing it to the original, assuming both images share the same resolution.

PSNR represents the ratio between the maximum possible power of a signal, which is the original image, and the power of the noise, which is based on the discrepancy between the original and processed images.

The PSNR value is expressed in decibels (dB) and provides a numerical value that quantifies the similarity between the two images.

High PSNR value

When the PSNR value is high, it indicates a higher level of similarity and better image quality between the original and processed images. A high PSNR value implies that the processed image has minimal distortion or noise compared to the original image.

Altogether this means that the image processing technique in use has effectively preserved the original image's details, colors, and overall visual appearance.

Low PSNR value

When the PSNR value is low, it indicates a higher level of distortion or noise in the processed image compared to the original image.

A low PSNR value suggests that the image processing technique in context has introduced significant changes or artifacts, resulting in a loss of visual fidelity.

Mathematical formula

SNRPEAK=10log10(L1)21N2r=0N1c=0N1(I^(r,c)I(r,c))2SNR_{PEAK} = 10 \log_{10}\frac{(L-1)^{2}}{\frac{1}{N^{2}} \sum_{r=0}^{N-1} \sum_{c=0}^{N-1} ( \hat I(r, c) - I(r, c))^2}

Here, the peak signal-to-noise ratio value is a logarithmic multiple of the ratio between signal and noise. L depends on the number of gray levels present in the image. For example, if an 8-bit representation is used in the image, the value ofLLwould be 256.

Moreover, r and c represent the row and column of the image, respectively. In turn, I(r,c)I(r,c) represents the original image's pixel present at row r and column c.

I^(r,c)\hat I(r, c) represents the reconstructed image's pixel present at row r and column c. Lastly, N^2 depicts the total number of pixels present in the image.

Python implementation to find the PSNR value

import React from 'react';
require('./style.css');

import ReactDOM from 'react-dom';
import App from './app.js';

ReactDOM.render(
  <App />, 
  document.getElementById('root')
);
Calculating PSNR value between original and processed image

Explanation

  • Lines 13: We define the libraries needed.

  • Lines 6–9: Here, a function called calculate_psnr() is defined. It takes three arguments: original_img (the original image), processed_img (the processed image), and max_pixel_value (the maximum pixel value for the image).

  • Lines 11–13: The code uses cv2.imread() to load the original and processed images from files. The images are read in grayscale mode (cv2.IMREAD_GRAYSCALE), assuming they are 8-bit grayscale images.

  • Lines 16–20: We ensure that the original and processed images have the same dimensions. The code uses cv2.resize() to resize the original image to match the dimensions of the processed image.

  • Lines 23–25: The maximum pixel value is set to 255 assuming 8-bit grayscale images. The calculate_psnr() function is called with the original and processed images along with the maximum pixel value. The calculated PSNR is stored in the psnr variable.

Summary

Peak signal-to-noise ratio (PSNR) serves as a valuable tool for assessing image quality in digital image processing. By quantifying the difference between the original and processed images, PSNR helps researchers, photographers, and imaging professionals gauge the effectiveness of their image enhancement techniques.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved