Ch. 3 · Anatomy of a Hybrid Codec

한국어日本語
7 min

DCT and Transform Coding: Why Codecs Convert Pixels to Frequencies

A transform packs a residual block's energy into a few frequency coefficients. Learn why codecs use the DCT, why standards use integer versions, and what MTS adds.

After prediction, what remains is the residual block. You could quantize and entropy-code it right away, but one more step comes first — the transform. It converts the spatial domain (pixel values) into the frequency domain (coefficients).

Why convert to frequency at all?

The residual of a natural image is usually a slowly varying signal. Decompose such a signal into frequencies and the energy gathers in a few low-frequency coefficients (overall brightness and tone changes), while the high-frequency (fine detail) coefficients are mostly close to 0. Once scattered information is 'concentrated' into a few large numbers, the quantization and entropy coding that follow work far more efficiently.

Residual block (spatial domain) 3-120 14-21 -203-1 01-12 Values spread evenly DCT coefficients (frequency domain) 18-210 -3100 1000 0000 Energy concentrated top-left (low freq.), near 0 bottom-right
The effect of the transform — turning a residual block (space) into DCT coefficients (frequency) concentrates the energy in the top-left

DCT — Discrete Cosine Transform

The transform codecs use overwhelmingly often is the DCT-II. In theory, for natural signals (approximated as a first-order Markov process), the DCT comes very close to the KLT (Karhunen-Loève Transform, the statistically optimal transform). The KLT has to be recomputed for each set of data, so it isn't practical, but the DCT achieves almost the same effect with a fixed set of basis functions.

An analogy

It's like transcribing a chord into sheet music. Instead of recording the complex air vibration coming out of a speaker (the spatial domain) as-is, you write it down as 'a chord mixing C, E, and G' (frequency components), and you can reproduce the same sound with much less information. In most music, a few main notes (low-frequency coefficients) hold most of the energy.

Integer transforms — what standards actually use

An important catch

Real codec standards don't use the pure DCT (real-number arithmetic). The encoder and decoder must produce bit-for-bit identical results (conformance, see Chapter 1), but floating-point arithmetic can have slightly different rounding errors across platforms and compilers. So the standards from H.264 onward define an integer transform that approximates the DCT. H.264 was the first to establish this approach, and every codec since has followed it.

Variable transform sizes and multiple transforms (VVC/AV1)

Early codecs used only fixed 4×4/8×8 DCTs, but recent codecs use a range of transform sizes from 4×4 up to 64×64 (or 32×32) to match the CU size, and even let the encoder choose the best of several transform kernels, such as the DST (Discrete Sine Transform) in addition to the DCT. VVC's MTS (Multiple Transform Selection) is the representative example. Some sharply directional edges suit the DST better, while smooth areas suit the DCT better.

DCTDiscrete Cosine Transform

A transform that decomposes a spatial signal into frequency components. A core tool of video codecs.

KLTKarhunen-Loève Transform

The statistically optimal transform. The DCT is a practical approximation of it.

Integer transformInteger transform

A standard transform that approximates the real-valued DCT with integer arithmetic, for conformance.

MTSMultiple Transform Selection

A VVC tool for choosing among several transform kernels such as DCT/DST.

Check yourself

Why do codec standards use integer transforms instead of the pure real-valued DCT?