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 and be two images with pixels. The mean squared error and the peak signal-to-noise ratio are
where and are the pixel values at , and is the data range: the largest value the pixel format allows (255 for 8-bit uint8 images, 1.0 for float images scaled to ). In scikit-image this is the data_range argument of skimage.metrics.peak_signal_noise_ratio. It is the same quantity as the used in IP 08, because .
Why decibels? Errors span many orders of magnitude, and the log makes equal ratios equal steps. Halving the MSE adds dB; halving the noise standard deviation (a quarter of the MSE) adds about 6.02 dB. A higher PSNR means a smaller error. Because 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 dBReading 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 ) adds dB and reports a spectacular 76.36 dB for the same image. Doubling nominally quadruples the MSE (a 6.02 dB drop); the measured drop is dB, a little less because clipping to 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
- R. C. Gonzalez and R. E. Woods, Digital Image Processing, 4th ed., Pearson, 2018, Ch. 2. publisher page
- M. Unser, “Sampling—50 years after Shannon,” Proceedings of the IEEE, vol. 88, no. 4, pp. 569–587, 2000. doi
- 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
- P. Thévenaz, T. Blu, and M. Unser, “Interpolation revisited,” IEEE Transactions on Medical Imaging, vol. 19, no. 7, pp. 739–758, 2000. doi
- A. Rosenfeld and J. L. Pfaltz, “Distance functions on digital pictures,” Pattern Recognition, vol. 1, pp. 33–61, 1968. doi
- B. Zitová and J. Flusser, “Image registration methods: a survey,” Image and Vision Computing, vol. 21, no. 11, pp. 977–1000, 2003. doi
- M. Delbracio, D. Kelly, M. S. Brown, and P. Milanfar, “Mobile computational photography: A tour,” arXiv:2102.09000, 2021. arXiv
- 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
- 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
- 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
- Y. Chen, S. Liu, and X. Wang, “Learning continuous image representation with local implicit image function,” CVPR, 2021. arXiv
- 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
- 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
- G. Zhai and X. Min, “Perceptual image quality assessment: A survey,” Science China Information Sciences, vol. 63, no. 11, 2020. doi
- 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
- 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
- C. Chen, Q. Chen, J. Xu, and V. Koltun, “Learning to see in the dark,” CVPR, 2018. arXiv
- A. Ignatov, L. Van Gool, and R. Timofte, “Replacing mobile camera ISP with a single deep learning model,” arXiv:2002.05509, 2020. arXiv
- 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
- R. Hartley and A. Zisserman, Multiple View Geometry in Computer Vision, 2nd ed., Cambridge University Press, 2004. doi
- scikit-image contributors, “ProjectiveTransform.estimate,” scikit-image 0.25.2 documentation, accessed 5 November 2026. API documentation.