Skip to main content

JPEG compression process steps

Short answer

JPEG compresses by preparing the image (YCbCr conversion, chroma subsampling, 8x8 blocks, level shift), applying DCT, quantizing coefficients (the lossy step), then zig-zag scanning with DPCM, RLE, and Huffman coding. Decoding reverses these steps; typical compression is 10:1 to 20:1.

Explain the steps of the JPEG compression process in detail (with example).

JPEG (Joint Photographic Experts Group) is a standard for compressing continuous-tone still images. The baseline (lossy, DCT-based) method has four main stages: preparation, DCT, quantization and entropy coding.

Image -> Preparation -> DCT -> Quantization
      -> Zig-zag + DPCM/RLE -> Huffman -> JPEG file

1. Image preparation

  • The image is split into components. An RGB image is usually converted to YCbCr (luminance Y and chrominance Cb, Cr).
  • Chroma subsampling: the eye is less sensitive to colour than brightness, so Cb and Cr are reduced, for example 4:2:0 (one chroma sample per 2x2 block of pixels). This alone halves the data.
  • Each component is divided into 8 x 8 blocks of pixels, and 128 is subtracted from each value (level shift) so values range from -128 to 127.

2. Discrete Cosine Transform (DCT)

  • A 2-D DCT is applied to each 8 x 8 block. It converts spatial pixel values into 64 frequency coefficients.
  • The top-left coefficient is the DC coefficient (average of the block); the other 63 are AC coefficients, growing in frequency toward the bottom-right.
  • DCT itself is nearly lossless; it only makes the data easier to compress, since most energy gathers in few low-frequency coefficients.

3. Quantization (the lossy step)

  • Each coefficient is divided by the matching entry of a quantization table and rounded to the nearest integer.
  • High-frequency entries have large divisors, so they become zero. Example: a coefficient 52 divided by 16 gives 3.25, rounded to 3; a high-frequency coefficient 7 divided by 99 rounds to 0.
  • A larger divisor means more compression and lower quality. This is the "quality" setting.

4. Entropy coding

  • Zig-zag scan: the 8 x 8 matrix is read in zig-zag order, giving a 1-D list with non-zero values first and a long tail of zeros.
  • DC coefficients are coded by DPCM: only the difference from the previous block's DC value is stored.
  • AC coefficients are coded by run-length encoding as (zeros-run, value) pairs, ending with an end-of-block (EOB) code.
  • The result is compressed with Huffman coding (or arithmetic coding), and written with headers to the JPEG file.

Mini example: after quantization a block's zig-zag list is 15, -2, 3, 0, 0, 1, 0, ... 0. It is stored as DC = 15 (as a difference), then (0,-2), (0,3), (2,1), EOB. Sixty-four values reduce to a few symbols.

Decoding reverses the steps: Huffman decode, de-quantize (multiply), inverse DCT, add 128, upsample chroma, convert to RGB. The quantization loss cannot be recovered. Typical compression is 10:1 to 20:1 with good quality.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Multimedia System chapter 5 questions →