Peak Signal-to-Noise Ratio as an Image Quality Metric

Publish Date: Jun 18, 2012 | 16 Ratings | 4.88 out of 5 |  PDF

Overview

This article describes the Peak Signal-to-Noise ratio as applied to images as a quality metric. The article describes developing the metrics in LabVIEW and suggests how they can be used. The functions are included as sample downloads.

Table of Contents

  1. Introduction
  2. Mathematics
  3. Motivation for Use as an Image Quality Metric
  4. How to build this function from base LabVIEW VIs and functions:
  5. Closing Notes
  6. Included Files
  7. Other Recommended Reading

 

1. Introduction

The term peak signal-to-noise ratio (PSNR) is an expression for the ratio between the maximum possible value (power) of a signal and the power of distorting noise that affects the quality of its representation.  Because many signals have a very wide dynamic range, (ratio between the largest and smallest possible values of a changeable quantity) the PSNR is usually expressed in terms of the logarithmic decibel scale.

Image enhancement or improving the visual quality of a digital image can be subjective.  Saying that one method provides a better quality image could vary from person to person.   For this reason, it is necessary to establish quantitative/empirical measures to compare the effects of image enhancement algorithms on image quality.
 
Using the same set of tests images, different image enhancement algorithms can be compared systematically to identify whether a particular algorithm produces better results.  The metric under investigation is the peak-signal-to-noise ratio.  If we can show that an algorithm or set of algorithms can enhance a degraded known image to more closely resemble the original, then we can more accurately conclude that it is a better algorithm.

 

Back to Top

2. Mathematics

For the following implementation, let us assume we are dealing with a standard 2D array of data or matrix.  The dimensions of the correct image matrix and the dimensions of the degraded image matrix must be identical.
The mathematical representation of the PSNR is as follows:

Figure 1 - Peak Signal-to-Noise Equation

where the MSE (Mean Squared Error) is:

Figure 2 - Mean Squared Error Equation

This can also be represented in a text based format as:

MSE = (1/(m*n))*sum(sum((f-g).^2))

PSNR = 20*log(max(max(f)))/((MSE)^0.5)

Legend:
f
represents the matrix data of our original image
g represents the matrix data of our degraded image in question
m represents the numbers of rows of pixels of the images and i represents the index of that row
n represents the number of columns of pixels of the image and j represents the index of that column
MAXf is the maximum signal value that exists in our original “known to be good” image

 

Back to Top

3. Motivation for Use as an Image Quality Metric

The mean squared error (MSE) for our practical purposes allows us to compare the “true” pixel values of our original image to our degraded image.   The MSE represents the average of the squares of the "errors" between our actual image and our noisy image. The error is the amount by which the values of the original image differ from the degraded image.

The proposal is that the higher the PSNR, the better degraded image has been reconstructed to match the original image and the better the reconstructive algorithm.  This would occur because we wish to minimize the MSE between images with respect the maximum signal value of the image.

 

Back to Top

4. How to build this function from base LabVIEW VIs and functions:

This method of quantitative image quality of assessment can be used for those who either do have or do not have access to the NI Vision Development Module.

Building the Mean Squared Error for 2D arrays VI:


We will start by creating two 2D arrays (remember to add another dimension) of doubles, naming one to be our expected or known good image and subtracting them.  The current front panel and block diagram or both shown in Figure 3.

Figure 3 - Building the MSE VI - Initial Front Panel and Block Diagram

Next, we will then use the absolute value function to ensure that all differences are positive as we are interested in the absolute error.  This function may seem redundant due to squaring each individual matrix value but this is recommended for completeness.  The block diagram should appear as in Figure 4.

Figure 4 - Taking the Absolute Value of the Difference between the Image Matrices

To be absolutely clear, we currently have a single matrix or 2D array that represents the difference between the pixel values of our desired image and our degraded image.  When we use LabVIEW’s square function, it squares each individual term within the matrix.  This is our desired result.  The following VI should appear as in Figure 5.

Figure 5 - Squaring Each Individual Matrix Element


In accordance with the equation, we then need to sum all elements of the array and this can be done easily using the Add Array Elements function.  The VI should now appear as in Figure 6.

Figure 6 - Summing the Elements of the Array

The next stage in the development of this VI is extract the dimensions of the image for the purpose of averaging the data.  This can be done using the Array Size function.  This is convenient as these two dimensions are now in an array. These values need to be multiplied together for the purpose of averaging the entire matrix data set.  This array of array dimensions can be passed into the Multiply Array Elements function to determine the total number of elements in the image array.  To accomplish this, the block diagram should appear as in Figure 7.

Figure 7 - Determining Total Number of Image Array Elements

The final step in creating this VI is to average the data, that is, divide the sum of the squares of matrix entries by the number of elements in the matrix.  This can be done using the divide function.  Adding an indicator here will represent the Mean Squared Error.  Error checking has also been included as well as proper documentation.  The connector pane and icon glyph have been set accordingly.  The final VI front panel and block diagram is shown in Figure 8.

Figure 8 - Final Front Panel and Block Diagram for the Mean Squared Error for 2D Arrays VI

 

Building the Peak Signal-to-Noise Ratio VI using the Mean Squared Error for 2D arrays


To set up the Peak Signal-to-noise Ratio VI, we will first create a new VI and again need two 2D arrays representing our expected image and our actual degraded image.  We will need to find the peak signal value using the Array Min Max function and the mean squared error between our two images in question using the VI that was previously constructed.  This is shown in a LabVIEW block diagram in Figure 9.

Figure 9 - Finding the Maximum Signal Value from the Expected Image and the Mean Squared Error between the Expected and Degraded Images

Next, we divide the maximum signal value from our expected image by the square root of the mean squared error to determine the ratio as shown in Figure 10.

Figure 10 - Dividing the Maximum Signal Value by the Mean Squared Error to Determine the Ratio

Finally, convert the output of this function to decibels and add an indicator to represent the output PSNR.  Error handling and documentation has also been implemented.  The final front panel and block diagram is shown in Figure 11.

Figure 11 - Final Front Panel and Block Diagram of the Peak Signal-to-Noise Ratio VI

 

Back to Top

5. Closing Notes

When you try to compute the MSE between two identical images, the value will be zero and hence the PSNR will be undefined (division by zero).  The main limitation of this metric is that it relies strictly on numeric comparison and does not actually take into account any level of biological factors of the human vision system such as the structural similarity index. (SSIM)

For colour images, the MSE is taken over all pixels values of each individual channel and is averaged with the number of colour channels.  Another option may be to simply perform the PSNR over a converted luminance or grayscale channel as the eye is generally four times more susceptible to luminance changes as opposed to changes in chrominance.  This approximation is left up to the experimenter.

The next tutorial will show the use of the PSNR and SSIM to assess image quality.

Back to Top

6. Included Files

The VIs developed in this tutorial are available for download below.  VI names have been named to specification and truncated to meet the 32 character limit.

For LabVIEW 2010/SP1

mse_for_2d_arrays.vi

psnr_for_2d_arrays.vi

For LabVIEW 2009/SP1

mse_for_2d_arrays_9.0.vi

psnr_for_2d_arrays_9.0.vi

For LabVIEW 8.6.1

mse_for_2d_arrays_8.6.1.vi

psnr_for_2d_arrays_8.6.1.vi

Back to Top

7. Other Recommended Reading

Structural Similarity Index Metric

Back to Top

Bookmark & Share

Ratings

Rate this document

Answered Your Question?
Yes No

Submit