Inverity
Codec Internals

How Lossy Image Compression Decides What to Discard

Author

Brandon Cade

Date Published

A band-pass luminance contrast-sensitivity curve peaking in the mid-frequencies and a low-pass chroma curve, overlaid on a faint 8x8 quantization matrix, with a crisp luminance swatch kept and a chroma swatch blurred.
TL;DR >- Human contrast sensitivity is band-pass for brightness, peaking near 4 cycles per degree and falling toward zero by roughly 60 cycles per degree (Wikipedia, Contrast sensitivity).- Color vision resolves far less fine detail than brightness: luminance sensitivity is band-pass, chromatic sensitivity is low-pass (NCBI PMC7405764, 2020).- The quantization matrix is essentially a coarse model of that vision curve, and each modern encoder bolts a different optimizer on top of it.- jpegli compresses high-quality images about 35% denser than traditional JPEG (2.8 vs 3.7 bits per pixel) using adaptive-quantization heuristics borrowed from JPEG XL (Google Open Source Blog, 2024).- Guetzli reaches 29 to 45% smaller files at a fixed perceptual distance by optimizing in a closed loop against the Butteraugli metric (arXiv 1703.04421, 2017).

"Lossy compression throws away detail your eye won't miss" is the most repeated and least explained sentence in this field. It raises the only question that matters and then answers none of it. Which detail? Measured how? And why does one encoder discard smarter than another at the same file size?

There is a real answer, and it forms a clean spine: a measured curve of human vision, a table that approximates that curve, and a per-encoder optimizer that refines the table for each image. Follow that spine and the differences between Guetzli, mozjpeg, and jpegli stop being brand names and become three distinct answers to one physiological question. For the wider map, start with our complete guide to image compression. Here we trace vision to matrix to encoder.

How does a compressor know what your eye won't notice?

It does not guess. It leans on measured limits of human vision, chiefly the contrast sensitivity function, which peaks near 4 cycles per degree and declines to roughly zero by about 60 cycles per degree (Wikipedia, Contrast sensitivity). Detail finer than your eye can resolve is safe to coarsen.

The contrast sensitivity function, or CSF, was mapped by Campbell and Robson in 1968 and has anchored perceptual coding ever since (Wikipedia, Contrast sensitivity). It is band-pass: your eye is most sensitive to mid-range spatial frequencies and much less sensitive to both very coarse and very fine ones. A compressor that spends bits in proportion to that curve keeps what you can see and drops what you cannot.

So the honest version of the cliche is specific. Lossy codecs discard high spatial frequencies first because your sensitivity to them is measurably low. The physics of that redundancy sets the ceiling; the vision curve decides which redundancy is safe to exploit.

The contrast sensitivity function is the hidden spec

Brightness and color are not equal, and that inequality drives half of image compression. Luminance sensitivity is band-pass, but the two chromatic channels are low-pass: the eye resolves far less high-frequency detail in color than in brightness (NCBI PMC7405764, 2020). That single fact justifies both chroma subsampling and coarser chroma quantization.

The wiring underneath explains why. Visual signals split across distinct pathways: the magnocellular pathway carries luminance, the parvocellular pathway carries red-green (L minus M) opponency, and the koniocellular pathway carries blue-yellow (S-cone) opponency (ScienceDirect, 2019). The color pathways simply do not resolve fine spatial detail the way the luminance pathway does, so throwing away high-frequency color information costs almost nothing perceptually.

This is why brightness edges survive aggressive compression while color edges blur. It is also the whole basis of chroma subsampling, where luma stays full resolution and chroma gets halved. The eye's asymmetry is not a quirk to work around. It is the resource the format spends.

Vision property

Luminance

Chroma

CSF shape

Band-pass, peak near 4 cpd

Low-pass

High-frequency detail

Well resolved

Poorly resolved

Neural pathway

Magnocellular

Parvocellular, koniocellular

Compression consequence

Kept at full resolution

Subsampled and quantized coarser

Line chart of contrast sensitivity versus spatial frequency, a band-pass luminance curve peaking near 4 cycles per degree and a low-pass chroma curve falling off earlier

Luminance sensitivity is band-pass and peaks near 4 cycles per degree; chroma sensitivity is low-pass and drops off far sooner (Campbell & Robson, 1968).

The quantization matrix is a coarse model of your eye

The standard JPEG quantization table is not arbitrary. It is a rough, static approximation of the contrast sensitivity function, weighting low frequencies finely and high frequencies coarsely so that bits land where the eye is sensitive. Because the CSF is band-pass, the table's high-frequency entries are large, which rounds fine detail toward zero.

We covered the byte-level mechanics of that table in how JPEG compression works. The point here is conceptual: quantization is where the vision curve becomes an actual operation on data. A hand-tuned table is a one-size-fits-all guess at human perception, fixed before the encoder ever sees your image. That is exactly the gap every modern encoder tries to close, and the reason two files at identical size can look very different, a theme we develop in PSNR vs SSIM vs looks-good-to-humans.

Why leave gains on the table with a fixed matrix? Because a static table cannot know that this block is busy texture and that block is smooth sky. Adapting to content is where the last 30-odd percent hides.

What is adaptive quantization, and when does it backfire?

Adaptive quantization varies the quantization strength per region using visual masking: busy, high-texture areas hide quantization noise, so the encoder spends fewer bits there and more on smooth areas where errors show. High local texture raises the threshold at which noise becomes visible, so the encoder can safely round harder inside detailed regions.

Masking is the lever. Put noise next to strong texture and your eye cannot separate the two; put the same noise in a clear sky and it reads as banding immediately. Adaptive quantization exploits this by moving bits from where they are wasted (busy regions) to where they are needed (smooth gradients). jpegli takes this further by enabling more than 10 bits per component inside the standard 8-bit-compatible JPEG bitstream, which directly reduces gradient banding (Google Open Source Blog, 2024).

When does it backfire? When the content is mostly smooth. Gradients, skies, and flat brand colors have little masking texture to hide behind, so aggressive quantization there produces visible banding rather than invisible savings. This is why content-adaptive per-image quality matters: the right amount of adaptation depends on what the image contains, and the same setting that helps a forest photo can wreck a sunset gradient.

How each modern encoder optimizes the table

Three well-known JPEG encoders share the same physiology but attack it differently, and the differences are concrete. Guetzli optimizes globally in a closed loop against a perceptual metric; mozjpeg searches per-coefficient with trellis quantization; jpegli imports JPEG XL's adaptive heuristics for speed. Same spec, three optimizers.

Guetzli runs a closed-loop optimizer over the global quantization tables and per-block DCT values, scoring candidates with the Butteraugli perceptual-distance metric, and reaches 29 to 45% smaller files for a given perceptual distance versus other compressors (arXiv 1703.04421, 2017). In a blind study, viewers preferred Guetzli's output over same-sized libjpeg JPEGs (arXiv 1703.04416, 2017). The cost is speed, which we get to next.

mozjpeg uses trellis quantization, a rate-distortion search over coefficient values borrowed from video coding, alongside progressive optimization and perceptually tuned tables. Its trellis modes can optimize against PSNR, HVS-PSNR, SSIM, or MS-SSIM depending on which metric you trust (mozjpeg README). Trellis quantization is not "round harder"; it is a Viterbi-style path search that picks the coefficient levels minimizing a combined rate-and-distortion cost, block by block.

jpegli takes a third route: it compresses high-quality images about 35% more than traditional JPEG, hitting 2.8 bits per pixel where libjpeg-turbo needs 3.7, using adaptive-quantization heuristics from JPEG XL at comparable speed (Google Open Source Blog, 2024). Those dead-zone heuristics were originally developed for Guetzli, then made much faster for JPEG XL and jpegli (arXiv 2506.05987, 2025). In other words, jpegli is Guetzli's perceptual insight with the crippling slowness engineered out.

Encoder

Core technique

Perceptual target

Reported gain

Guetzli

Closed-loop global optimization

Butteraugli distance

29 to 45% smaller at fixed distance

mozjpeg

Trellis (rate-distortion) quantization

PSNR / HVS-PSNR / SSIM / MS-SSIM

Not stated numerically by its docs

jpegli

JPEG XL adaptive-quant dead-zone heuristics

Perceptual, high-fidelity

About 35% denser (2.8 vs 3.7 bpp)

Guetzli: arXiv 1703.04421, 2017. mozjpeg: README. jpegli: Google Open Source Blog, 2024.

Bar chart of reported size reduction versus a libjpeg-turbo baseline for mozjpeg, jpegli and Guetzli, annotated with relative encode speed

Reported reductions vs libjpeg-turbo on different measurement bases: jpegli about 35% denser at equal quality, Guetzli 29 to 45% smaller at a fixed perceptual distance but far slower, mozjpeg unquantified in its docs (Google Open Source Blog, 2024; arXiv 1703.04421, 2017).

Is Guetzli worth the speed cost in 2026?

For most pipelines, no, because jpegli captures much of the perceptual insight without the crippling slowness. Guetzli's own paper describes it only as "extremely slow," and industry estimates put it orders of magnitude slower than mozjpeg (arXiv 1703.04421, 2017). That cost was defensible when nothing else optimized perceptually. It is harder to defend now.

The reason is lineage. jpegli's dead-zone heuristics trace back to Guetzli, then were re-engineered to run at roughly normal JPEG speed inside JPEG XL and jpegli (arXiv 2506.05987, 2025). You get most of the perceptual benefit at a fraction of the compute. For a one-off master where every byte counts and time is free, Guetzli can still be worth running. For a pipeline encoding thousands of images, jpegli or a well-tuned mozjpeg is the pragmatic choice, and picking between them is the subject of tuning mozjpeg, libjxl, and libaom.

The larger lesson is that "which encoder" is downstream of "which perceptual target." Once you decide how you will measure quality the way humans see it, covered in measuring quality the way humans see it and in how AI models judge visual quality, the encoder is just the tool that hits it cheapest.

FAQ

How does a compressor know what the eye won't notice?

It uses measured vision limits, mainly the contrast sensitivity function, which peaks near 4 cycles per degree and falls toward zero by about 60 (Wikipedia, Contrast sensitivity). Frequencies your eye resolves poorly get quantized coarsely. The quantization table is a static approximation of that curve, refined per image by modern encoders.

Why keep brightness detail but blur color?

Because color vision resolves far less fine detail than brightness. Luminance sensitivity is band-pass while chromatic sensitivity is low-pass (NCBI PMC7405764, 2020), a difference rooted in separate neural pathways (ScienceDirect, 2019). Discarding high-frequency color detail is nearly invisible, which is why chroma is subsampled and quantized more coarsely than luma.

Is trellis quantization just rounding harder?

No. Trellis quantization is a rate-distortion path search over coefficient values, borrowed from video coding, that picks the levels minimizing combined size and distortion (mozjpeg README). Simple quantization rounds each coefficient independently; trellis evaluates sequences of choices to find a cheaper, lower-distortion combination across the block.

Is Guetzli still worth it, or is jpegli enough now?

For most workflows, jpegli is enough. It reaches about 35% denser output than traditional JPEG at comparable speed (Google Open Source Blog, 2024), using heuristics descended from Guetzli. Guetzli reaches 29 to 45% smaller files at a fixed perceptual distance (arXiv 1703.04421, 2017) but runs orders of magnitude slower, so reserve it for offline masters.

What is adaptive quantization, and when does it hurt?

Adaptive quantization varies compression strength by region, spending fewer bits where texture masks noise and more where errors show. It helps busy, detailed images. It hurts on smooth content: gradients and flat colors lack masking texture, so aggressive quantization produces visible banding. jpegli counters banding with 10-plus-bit internal precision (Google Open Source Blog, 2024).

The spine that ties it together

Lossy compression is not magic and it is not guesswork. It is a measured curve of human vision, a table that approximates that curve, and an optimizer that refines the table for the image in front of it. Guetzli, mozjpeg, and jpegli differ only in that last step: closed-loop perceptual search, trellis rate-distortion, or borrowed JPEG XL heuristics. The physiology underneath is shared and settled.

That framing has a practical payoff. If you choose your perceptual target first, then the encoder question answers itself, and you stop chasing file size as a proxy for quality it never measured. At Inverity, we treat the perceptual metric as the contract and the encoder as an interchangeable way to satisfy it, an approach we lay out in beyond compression, perceptual decisioning. Decide what the eye needs, and the discard decisions make themselves.