Lempel-Ziv Coding
- dictionary encoding
- near-optimal
- find a sequence s of bits (length l > 0) not in the dictionary
- subsequence of length l - 1 must be in dictionary
- encode s as the position of the left substring, plus the new bit
- number of bits to encode position is log2 (|dictionary|)
- decoding consists of following pointer
Lempel-Ziv Example
1110 1101 000 11 ...
- 1
- 1, pointer to 1 (a) followed by bit 1
- 1, a/1, 0
- 1, a/1, 0, pointer to 11 (b) /0
- 1, a/1, 0, b/0, c/1
- 1, a/1, 0, b/0, c/1, c/0
- 1, a/1, 0, b/0, c/1, c/0, e/1
- ...
Differential Pulse Code Modulation
- DPCM
- start with a reference symbol
- then only list the differences between successive symbols.
- Example:
- data (24 bits) is 0000 0001 0001 0010 1001 1000
- compressed to 0 (symbol), +1, +0, +1, 9 (new symbol), -1
- encoded by 2 bits for difference
- code 10 marks a new symbol
- 10.0000 01 00 01 10.1001 11
- Compression ratio 20 / 24 = 5/6.
DCPM Characteristics
- lossless.
- like RLE, but allows small variations in the data
(e.g. real-world images).
- good for reducing the dynamic range of pixel values (adjacent
pixels are usually similar).
GIF image compression
- Graphical Interchange Format
- lossy compression for 24-bit color images.
- identify the colors used in the picture.
- select 256 colors, replace 24-byte pixels with 8-byte indices into table
(lossy).
- Run LZ over result (sequences of pixels are the "strings").
- Up to 10-to-1 compression ratio (10%).
JPEG image compression
- Joint Photographic Experts Group
- lossy compression for color images
- Color (RGB or YUV) separation (steps following are for each color).
- Divide into 8 * 8 blocks.
- Discrete Cosine Transform (DCT) on each block.
- Quantization (lossy).
- RLE/DPCM Encoding
- JPEG standard lets the compression quality be traded against image
quality and viceversa.
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.
- 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
- the lowest spatial frequencies are most
important for picture quality (for humans)
- JPEG uses more bits for the low spatial frequency components.
- Only the more significant bits of higher spatial
frequency components are retained
- achieved by dividing each coefficient by a value stored in a table
(larger values for larger frequencies)
- example: value for (0,0) might be 4, so only the 2 least
significant bits are lost.
- example: value 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.
- variant: only the length of runs of zero values are encoded
- high-frequency components have been divided by larger values,
so they tend to be zero
- codewords for Huffman coding are length of zero-run and following
non-zero value
- DC coefficient is likely to be the same as in the previous
block, and is encoded using DPCM.