To calculate Peak Signal-to-Noise Ratio (PSNR), you must first find the Mean Squared Error (MSE) between a reference image and a distorted image, then apply a logarithmic scale based on the maximum possible pixel value.
PSNR is a standard metric used to measure the quality of reconstruction in image and video compression codecs.
Here is the step-by-step mathematical guide to calculating it. 1. Identify Image Dimensions and Peak Value
Before calculating, identify the physical parameters of your images. Both the original image I and reconstructed image K must have identical dimensions.
Dimensions: Let M be the image height (rows) and N be the image width (columns). Peak Value ( MAXIcap M cap A cap X sub cap I ): This is the maximum possible pixel value of the image. For a standard 8-bit grayscale or color channel image: For a 12-bit image: For a 16-bit image: 2. Compute Mean Squared Error (MSE)
The MSE measures the average squared difference between the corresponding pixels of the original image I and the distorted image K. Compute it using the formula:
MSE=1M⋅N∑i=0M−1∑j=0N−1[I(i,j)−K(i,j)]2cap M cap S cap E equals the fraction with numerator 1 and denominator cap M center dot cap N end-fraction sum from i equals 0 to cap M minus 1 of sum from j equals 0 to cap N minus 1 of open bracket cap I open paren i comma j close paren minus cap K open paren i comma j close paren close bracket squared Execution steps:
Subtract the intensity value of pixel (i,j) in the distorted image from the same pixel in the original image.
Square this difference to eliminate negative values and penalize larger errors.
Sum these squared values for every single pixel across all rows (M) and columns (N).
Divide the total sum by the total number of pixels (M ⋅ N). 3. Apply the PSNR Formula
Once you have the MSE, convert it to a decibel (dB) scale using the mathematical definition of PSNR:
PSNR=10⋅log10(MAXI2MSE)cap P cap S cap N cap R equals 10 center dot log base 10 of open paren the fraction with numerator cap M cap A cap X sub cap I squared and denominator cap M cap S cap E end-fraction close paren Alternatively, this can be written as:
PSNR=20⋅log10(MAXIMSE)cap P cap S cap N cap R equals 20 center dot log base 10 of open paren the fraction with numerator cap M cap A cap X sub cap I and denominator the square root of cap M cap S cap E end-root end-fraction close paren Execution steps: Divide the squared maximum pixel value ( MAXI2cap M cap A cap X sub cap I squared ) by your calculated MSE. Take the base-10 logarithm ( log10log base 10 of ) of that result.
Multiply the final number by 10. The resulting unit is decibels (dB). 4. Interpret Your Results
The calculated PSNR value directly correlates with image fidelity:
Higher PSNR indicates a higher quality image that closely matches the original.
Lower PSNR signifies a highly compressed or degraded image with visible artifacts.
Typical Values: For lossy image and video compression (like JPEG), acceptable PSNR values generally range between 30 dB and 50 dB for 8-bit images.
Infinite PSNR: If the MSE is exactly 0 (the images are identical), dividing by zero yields an undefined value, which represents an infinite (∞) PSNR. ✅ Summary of PSNR Calculation
To calculate PSNR, you must find the Mean Squared Error (MSE) between the original and altered images, divide the squared maximum possible pixel value by the MSE, and convert the result to decibels using a base-10 logarithm.
If you are implementing this computationally, I can write a script to handle it automatically. Let me know:
Which programming language you prefer (Python, MATLAB, C++)?
Leave a Reply