JPEG image compression

Joint Photographic Experts Group: lossy compression for color images.

  1. Color (RGB or YUV) separation (steps following are for each color).
  2. Divide into 8 * 8 blocks.
  3. Discrete Cosine Transform (DCT) on each block.
  4. Quantization (lossy).
  5. RLE/DPCM Encoding

JPEG standard lets the compression quality be traded against image quality and viceversa.


Notes:


How many people have heard of FFT?



JPEG DCT

Discrete Cosine Transform is similar to Fast Fourier Transform (FFT).

DCT computes spatial frequencies for a data set (for JPEG, for an 8 * 8 block).

Except for quantization errors, the spatial frequencies can be converted (using inverse DCT) back into the data set, so DCT is not lossy.

Intuition: spatial frequency (0, 0) is the "DC", "constant", or "offset" for the entire block (how light or dark the entire block is). Higher frequencies correspond to variations in the image: highest frequencies are the sharpest edges.



JPEG Quantization

As judged by human viewers, the lowest spatial frequencies are most important for picture quality.

JPEG uses more bits for the low spatial frequency components. Only the more significant bits of higher spatial frequency components are retained.

The exact algorithm is to divide each spatial frequency (the result of the DCT phase) by a corresponding coefficient stored in a table. The table has small coefficients for low frequencies and large coefficients for high frequencies.

For example, the coefficient for (0,0) might be 4, so only the 2 least significant bits are lost. The coefficient for (7,7) might be 32, so the 5 least significant bits are lost.

JPEG specifies a set of quantization tables.



JPEG Encoding

JPEG uses a variant of run-length encoding in a diagonal pattern over the data produced by quantization.

The variant is that only the length of runs of zero values are encoded -- all other values are encoded as themselves. Since many of the higher-frequency components have been divided by large coefficients, they are likely to be zero.

Also, the DC coefficient is likely to be the same as in the previous block, and is encoded using DPCM.


Notes:


Draw picture of diagonal pattern, also book figure 7.12.



Summary