Ch. 4 · Image Codecs

한국어日本語
6 min

How JPEG Works (1): DCT, Quantization and the Compression Pipeline

How does JPEG compress an image? It is the video codec pipeline from Chapter 3 with prediction removed: 8×8 DCT, quantization and Huffman coding, step by step.

JPEG (Joint Photographic Experts Group), standardized in 1992, has survived for more than 30 years and is the most widely used image format in history. Surprisingly, it has almost the same skeleton as the video codec pipeline from Chapter 3. In a sense, video codecs extend JPEG's ideas along the time axis.

Color spaceconversion 8×8 DCTblocks + transform Quantization Zig-zagscan order Huffmancoding Note: no intra prediction, no inter prediction — blocks are transformed as they are
The JPEG pipeline — the six steps of Chapter 3, minus 'motion prediction'
StageHow JPEG does itCompared with the Chapter 3 video codecs
Color spaceRGB → YCbCr, usually 4:2:0Same (exactly as in Chapter 1)
Block partitioningFixed 8×8, no splittingHEVC/AV1 use variable partitioning (Chapter 3)
PredictionNone (only the DC coefficient is differenced against the previous block)Video uses sophisticated intra/inter prediction
TransformFixed 8×8 DCTModern video codecs use variable sizes and multiple transforms
Entropy codingHuffman coding (fixed or custom tables)Video mostly uses CABAC (arithmetic coding)

JPEG is the 'simplest version' of a video codec. The key difference is that it has no prediction.

Key insight

If you understand JPEG, you have effectively understood intra-frame (keyframe) coding in video codecs. The intra frames of HEVC and AV1 are close to 'JPEG plus dozens of prediction modes and variable block partitioning'.

DC and AC coefficients — the one remaining trace of 'prediction'

Of the 64 coefficients produced by the 8×8 DCT, the one in the top-left corner is the DC coefficient (the average brightness of the block), and the other 63 are AC coefficients (detail). JPEG codes only the DC coefficients differentially between neighboring blocks (DPCM) — this is the only trace of 'prediction' left in JPEG.

Why blocking artifacts stand out so much

JPEG has no in-loop filter like the one you learned about in Chapter 3. That is why the 8×8 grid pattern (blocking artifacts) is so conspicuous in low-quality JPEGs. The deblocking filters introduced by later video codecs were, in part, a correction of this weakness from the JPEG era.

JPEGJPEG

Standardized in 1992, the original block-based DCT lossy image compression format.

DC coefficientDC coefficient

The transform coefficient that represents the average brightness of a block. It is coded as a difference from the neighboring block.

AC coefficientAC coefficient

The 63 frequency coefficients other than DC. They carry the detail information.

Huffman codingHuffman coding

Lossless entropy coding that assigns a whole number of bits to each symbol according to its probability. Used in JPEG's final stage.

Check yourself

What is the most fundamental structural difference between JPEG and the intra frames of modern video codecs?