Full search page →

MSE, PSNR and the data range

Optional · supplementary note 5 of 5 for IP 02 · Digital Image Fundamentals. Nothing in the main text depends on it; citation numbers refer to the reference list at the bottom of this page.

Navigate: this page and this track: Navigate: this page and this track

How far is a processed image from the original? The simplest answer averages the squared pixel differences. That number is hard to read on its own (is 100 large?), so we compare it with the largest value a pixel can take and report the ratio on a logarithmic scale, like the decibels of sound level.

Let ff and f^\hat f be two images with MNMN pixels. The mean squared error and the peak signal-to-noise ratio are

MSE=1MN∑x,y(f^(x,y)−f(x,y))2,PSNR=10log⁡10MAX2MSE dB,\text{MSE} = \frac{1}{MN}\sum_{x,y}\big(\hat f(x,y) - f(x,y)\big)^2, \qquad \text{PSNR} = 10\log_{10}\frac{\text{MAX}^2}{\text{MSE}}\ \text{dB},

where f(x,y)f(x,y) and f^(x,y)\hat f(x,y) are the pixel values at (x,y)(x,y), and MAX\text{MAX} is the data range: the largest value the pixel format allows (255 for 8-bit uint8 images, 1.0 for float images scaled to [0,1][0, 1]). In scikit-image this is the data_range argument of skimage.metrics.peak_signal_noise_ratio. It is the same quantity as the 20log⁡10(Lmax⁡/erms)20\log_{10}(L_{\max}/e_{\text{rms}}) used in IP 08, because erms=MSEe_{\text{rms}} = \sqrt{\text{MSE}}.

Why decibels? Errors span many orders of magnitude, and the log makes equal ratios equal steps. Halving the MSE adds 10log⁡102≈3.0110\log_{10} 2 \approx 3.01 dB; halving the noise standard deviation (a quarter of the MSE) adds about 6.02 dB. A higher PSNR means a smaller error. Because MAX\text{MAX} sits inside the formula, the same pixel error gives a different PSNR if you change it, so a PSNR is only meaningful together with its range.

Code · Python · 21 lines
import numpy as np
from skimage import color, data
from skimage.metrics import mean_squared_error, peak_signal_noise_ratio

ref = data.camera()                              # uint8, values 0..255
rng = np.random.default_rng(0)
for sigma in (10, 20):
    noisy = np.clip(ref + rng.normal(0, sigma, ref.shape), 0, 255).astype(np.uint8)
    mse = mean_squared_error(ref, noisy)
    print(f"sigma={sigma}: MSE={mse:.1f}, by hand {10 * np.log10(255**2 / mse):.2f} dB, "
          f"uint8 {peak_signal_noise_ratio(ref, noisy):.2f} dB")
    ref_f, noisy_f = ref / 255.0, noisy / 255.0  # the same pair as floats in [0, 1]
    print(f"   float, data_range=1.0: {peak_signal_noise_ratio(ref_f, noisy_f, data_range=1.0):.2f} dB")
    print(f"   float, data_range=255: {peak_signal_noise_ratio(ref_f, noisy_f, data_range=255):.2f} dB  (wrong)")

# Pitfall: the same noise on RGB and on luma Y gives different PSNR
rgb = data.astronaut()
noisy_rgb = np.clip(rgb + rng.normal(0, 10, rgb.shape), 0, 255).astype(np.uint8)
y = lambda im: color.rgb2gray(im) * 255          # luma in [0, 255]
print(f"RGB: {peak_signal_noise_ratio(rgb, noisy_rgb):.2f} dB, "
      f"Y: {peak_signal_noise_ratio(y(rgb), y(noisy_rgb), data_range=255):.2f} dB")

The run prints:

Code · 7 lines
sigma=10: MSE=97.8, by hand 28.23 dB, uint8 28.23 dB
   float, data_range=1.0: 28.23 dB
   float, data_range=255: 76.36 dB  (wrong)
sigma=20: MSE=374.0, by hand 22.40 dB, uint8 22.40 dB
   float, data_range=1.0: 22.40 dB
   float, data_range=255: 70.53 dB  (wrong)
RGB: 28.61 dB, Y: 31.03 dB

Reading the numbers: the uint8 pair and the float pair give the same 28.23 dB when the range matches the scale of the values, but declaring the wrong range (255 for floats in [0,1][0, 1]) adds 20log⁡10255≈48.1320\log_{10} 255 \approx 48.13 dB and reports a spectacular 76.36 dB for the same image. Doubling σ\sigma nominally quadruples the MSE (a 6.02 dB drop); the measured drop is 28.23−22.40=5.8328.23 - 22.40 = 5.83 dB, a little less because clipping to [0,255][0, 255] removes part of the added error at saturated pixels. The last line shows the third pitfall: the same noise scores 28.61 dB on RGB and 31.03 dB on the luma channel Y, because Y averages three independent noisy channels. Compare PSNR values only when the images, the range, and the channels (RGB or Y) are the same, and convert integer images to float before subtracting, or uint8 arithmetic wraps around (scikit-image does this internally).

Finally, PSNR measures pixel error, not appearance. Two images with the same PSNR can look very different, and structure-aware indices such as SSIM [13], or learned perceptual distances [15], track human judgments better; see the Modern view above. Huynh-Thu and Ghanbari [19] discuss the scope within which PSNR is a valid quality measure.

References

  1. R. C. Gonzalez and R. E. Woods, Digital Image Processing, 4th ed., Pearson, 2018, Ch. 2. publisher page
  2. M. Unser, “Sampling—50 years after Shannon,” Proceedings of the IEEE, vol. 88, no. 4, pp. 569–587, 2000. doi
  3. R. Keys, “Cubic convolution interpolation for digital image processing,” IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 29, no. 6, pp. 1153–1160, 1981. doi
  4. P. Thévenaz, T. Blu, and M. Unser, “Interpolation revisited,” IEEE Transactions on Medical Imaging, vol. 19, no. 7, pp. 739–758, 2000. doi
  5. A. Rosenfeld and J. L. Pfaltz, “Distance functions on digital pictures,” Pattern Recognition, vol. 1, pp. 33–61, 1968. doi
  6. B. Zitová and J. Flusser, “Image registration methods: a survey,” Image and Vision Computing, vol. 21, no. 11, pp. 977–1000, 2003. doi
  7. M. Delbracio, D. Kelly, M. S. Brown, and P. Milanfar, “Mobile computational photography: A tour,” arXiv:2102.09000, 2021. arXiv
  8. R. Ramanath, W. E. Snyder, Y. Yoo, and M. S. Drew, “Color image processing pipeline,” IEEE Signal Processing Magazine, vol. 22, no. 1, pp. 34–43, 2005. doi
  9. Z. Wang, J. Chen, and S. C. H. Hoi, “Deep learning for image super-resolution: A survey,” IEEE Transactions on Pattern Analysis and Machine Intelligence, 2020. arXiv
  10. B. Moser, F. Raue, S. Frolov, J. Hees, S. Palacio, and A. Dengel, “Hitchhiker’s guide to super-resolution: Introduction and recent advances,” IEEE Transactions on Pattern Analysis and Machine Intelligence, 2023. arXiv
  11. Y. Chen, S. Liu, and X. Wang, “Learning continuous image representation with local implicit image function,” CVPR, 2021. arXiv
  12. X. Wang, L. Xie, C. Dong, and Y. Shan, “Real-ESRGAN: Training real-world blind super-resolution with pure synthetic data,” arXiv:2107.10833, 2021. arXiv
  13. Z. Wang, A. C. Bovik, H. R. Sheikh, and E. P. Simoncelli, “Image quality assessment: From error visibility to structural similarity,” IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600–612, 2004. project page
  14. G. Zhai and X. Min, “Perceptual image quality assessment: A survey,” Science China Information Sciences, vol. 63, no. 11, 2020. doi
  15. R. Zhang, P. Isola, A. A. Efros, E. Shechtman, and O. Wang, “The unreasonable effectiveness of deep features as a perceptual metric,” CVPR, 2018. arXiv
  16. K. Ding, K. Ma, S. Wang, and E. P. Simoncelli, “Comparison of full-reference image quality models for optimization of image processing systems,” International Journal of Computer Vision, 2021. arXiv
  17. C. Chen, Q. Chen, J. Xu, and V. Koltun, “Learning to see in the dark,” CVPR, 2018. arXiv
  18. A. Ignatov, L. Van Gool, and R. Timofte, “Replacing mobile camera ISP with a single deep learning model,” arXiv:2002.05509, 2020. arXiv
  19. Q. Huynh-Thu and M. Ghanbari, “Scope of validity of PSNR in image/video quality assessment,” Electronics Letters, vol. 44, no. 13, pp. 800–801, 2008. doi
  20. R. Hartley and A. Zisserman, Multiple View Geometry in Computer Vision, 2nd ed., Cambridge University Press, 2004. doi
  21. scikit-image contributors, “ProjectiveTransform.estimate,” scikit-image 0.25.2 documentation, accessed 5 November 2026. API documentation.