Multimedia & Machine Learning Algorithms · Multimedia Algorithms
JPEG Standard — DCT, Quantization & Entropy Coding
Explanation
Intuition
The human eye is far more sensitive to subtle intensity changes than to high-frequency fine details. JPEG exploits this: it transforms each block to the frequency domain (DCT), then quantizes (rounds and divides) the high-frequency coefficients with lower precision. The reconstruction is not exact — this is lossy compression.
Step 1 — Block Splitting & Level Shift
1. Convert to YCbCr color space; optionally downsample the Cb/Cr channels.
2. Divide each channel into pixel blocks.
3. Level shift: Subtract 128 from each value, shifting from to .
Step 2 — 2D DCT
Discrete Cosine Transform (DCT-II) for an block:
where and for all .
- — DC coefficient: proportional to block average.
- with — AC coefficients: increasing spatial frequencies.
Energy compaction property: Smooth regions concentrate nearly all energy in and nearby low-frequency coefficients — most AC coefficients are near zero.
Step 3 — Quantization
Each coefficient is divided by its entry in the quantization table and rounded to an integer:
The table has larger values for high frequencies — so high-frequency coefficients are coarsely rounded, and many become zero. This is the only lossy step in JPEG. The Quality Factor (typically –) scales the table: **larger = finer quantization = larger file but higher quality** (: near-lossless; : maximum compression, low quality).
> Note: The standard JPEG quantization table is not reproduced here — see ISO 10918-1. Exercises below use simple illustrative tables.
Step 4 — Zigzag Scan
The 64 quantized coefficients are arranged into a 1D array in "zigzag" order — DC first, then ACs in increasing-frequency order. This groups all non-zero coefficients near the beginning and produces a long trailing run of zeros — ideal for compression.
Step 5 — Entropy Coding
DC coefficient: Differential coding — the difference between consecutive blocks (neighboring DCs are close). Then Huffman coding.
AC coefficients: Run-Length Encoding (RLE): each group specifies "how many zeros before" and the next non-zero value. A special EOB (End of Block) symbol marks that all remaining ACs are zero. Then Huffman coding.
Interactive Visualization
Loading visualization
Worked Examples
Practice
Exercise 1 of 6
1
At which step of the JPEG process is information lost (perfect reconstruction is impossible)?
★Quiz
Test your knowledge from this lesson
A mix of questions from the lesson — each attempt varies slightly
Answer at least 4 out of 5 questions correctly to pass (70%)