Compressed vs original: reading PSNR, SSIM and diffs

Measured JPEG and WebP examples: what PSNR and SSIM say, why they disagree, how chroma subsampling skews them, and how to pick a quality.

On this page

"Quality 75" means nothing on its own: the same setting gives a perfect result on one picture and visible blocks on another. The reliable way to choose compression is to compare the result with the original, by eye and with numbers. This article explains the two numbers most tools report, PSNR and SSIM, with measurements from one test picture, and shows where each misleads. All values were computed with the image comparison tool's own code.

The test picture

The test picture is an 800 × 600 rendering of the Mandelbrot set made with FFmpeg: very saturated colours, fine detail at the edges and smooth gradients elsewhere, a deliberately hard case. As a PNG (lossless) it is 311 KB. It was saved as JPEG with Pillow at several qualities, once with its default settings and once with chroma subsampling turned off, and as WebP at quality 75.

What PSNR and SSIM measure

PSNR (peak signal-to-noise ratio) is the mean squared error between the two pictures, expressed on a logarithmic scale: 10 · log₁₀(255² / MSE), in decibels. Two flat grey pictures of value 100 and 110 differ by 10 everywhere, so MSE is 100 and PSNR is 28.13 dB. Identical pictures give infinity. It is simple, exact and blind to where the error is.

SSIM (structural similarity, Wang and colleagues, 2004) compares the pictures in small windows, here 8 × 8 pixels every 4 pixels, on brightness. For each window it combines three things: whether the average brightness matches, whether the contrast matches, and whether the pattern matches. The result is averaged over the picture: 1 means identical. Because the eye is more sensitive to broken structure than to an even shift, SSIM usually tracks what people notice better than PSNR does.

The measurements

VersionSizePSNRSSIM
JPEG q95, default (4:2:0)92 KB26.32 dB0.9976
JPEG q85, default53 KB26.13 dB0.9945
JPEG q75, default40 KB25.81 dB0.9907
JPEG q50, default27 KB24.92 dB0.9826
JPEG q25, default19 KB24.00 dB0.9663
JPEG q95, no subsampling (4:4:4)158 KB45.23 dB0.9977
JPEG q75, no subsampling70 KB33.89 dB0.9910
WebP q7527 KB26.08 dB0.9915

Two things stand out.

PSNR barely moves from quality 95 to 25 with default settings (26.3 to 24.0 dB), while the file shrinks almost five times. SSIM falls more clearly, from 0.998 to 0.966, and that matches what you see with the slider: at q25 there are visible blocks along the fractal's edges, at q95 there are none.

Chroma subsampling dominates PSNR. JPEG normally stores colour at half resolution in each direction (4:2:0), because the eye resolves brightness far better than colour. On this extremely saturated picture that alone costs about 19 dB: q95 is 26.32 dB with subsampling and 45.23 dB without. SSIM, measured on brightness, is the same in both cases (0.9976 against 0.9977). Neither number is wrong: the colour edges really are softer, and the brightness really is preserved. For normal photographs the effect is much smaller, but it explains many "low PSNR, looks fine" surprises.

Use the difference view

Numbers summarise; the difference view shows where. It paints matching pixels black and differences in grey, amplified four times. On the q75 JPEG the differences hug every sharp edge of the fractal (ringing and blocks), while the flat areas stay black. On a photo you would see the same around hair, text and leaves. If the differences sit in places nobody looks at, the compression is fine whatever the numbers say.

A practical method for choosing quality

  1. Export three versions with the image toolkit, for example quality 85, 75 and 60.
  2. Open the original and each version in the comparison tool. Zoom to 2× on faces, text and smooth gradients, the places compression fails first.
  3. Keep the smallest version where you cannot see a difference with the slider at 100% zoom. As a rough guide, SSIM at or above 0.98 is usually safe; below 0.95, look carefully.
  4. Check the saving the tool shows. On the test picture, default q75 is 87% smaller than the PNG; going to q50 saves another 13 KB at a visible cost.

Common mistakes

  • Judging by PSNR alone. It can stay flat while blocks appear, and drop for colour changes nobody sees.
  • Comparing at a different size. A picture scaled down hides compression errors. Compare at 100% or zoomed in, at the size people will see it.
  • Comparing against an already compressed "original". Measure against the best version you have, ideally the PNG or the camera's file.
  • Re-encoding repeatedly. Each JPEG save adds error; edit from the original and export once.
  • Forgetting the format. WebP at q75 was smaller than JPEG at q50 here with better SSIM (0.9915 against 0.9826). If the destination supports it, it is often the better trade.

Summary

SSIM tells you whether the structure survived, PSNR whether the values did, and the difference view where they did not. Use all three, decide at the size the picture will be seen, and let the file size be the tie-breaker.

Tools mentioned in this article

Back to the blog