Run-Length Encoding
Encode sequences of identical symbols as (symbol,count) pairs. Can use xed-size counts or special prexes to indicate the number of bits for the count
Fixed: can reduce compression if either too large or too small Variable: overhead for the prexes
Lempel-Ziv-Welch
Basic idea: encode longest possible previously-seen sequence Coding stream is mixture of symbols and back-pointers Better yet:
Keep a codebook of previously-seen sequences Store codebook index instead of backwards pointers.
Used in most common text compression algorithms, zip, and the GIF image standard.
Useful for binary signals and black-and-white images. 2-D RLE is used in the CCITT fax standard.
Compression (contd) Interpixel Redundancy Repetition Compression (contd) Interpixel Redundancy Repetition
Lempel-Ziv-Welch
Example: Lempel-Ziv
codebook = all single symbols sequence = empty while (get(symbol)) if sequence + symbol is in codebook sequence += symbol else output(code for sequence) add sequence + symbol to codebook sequence = symbol
Mary had a little lamb, little lamb, little lamb, Mary had a little lamb, its fleece was white as snow.
Predictive Coding
Predictive Coding
Key: Sender and receiver use the same predictive model. Sender Make prediction (no peeking!) Send the residual (difference) Receiver Make prediction Add the residual to get the correct value
The error from the prediction (residual) hopefully has smaller entropy than the original signal. The information used to make the prediction is the context.
Delta Modulation
Basic Algorithm:
Prediction: next signal value is the same as the last. Residual is the difference (delta) from the previous one. Residual is encoded in a smaller number of bits than the original.
Often used in audio systems (phones). Problem: limited-range delta can cause under/overshoot.
Simplest predictor: average of the four neighbors Can use larger context Can quantize (lossy) or entropy code (lossless) the residual Used in DPCM and the lossless part of the JPEG standard. Newer algorithms (CALOC, LOCO-I) use multiple contexts and smarter predictors.
Perceptual Redundancy
Eye is less sensitive to Color High Frequencies So, Allocate more bits/samples to intensity than chromaticity. Allocate more bits to low frequencies than to high frequencies Can play similar tricks with the ear and varying sensitivity to different frequencies (e.g., the psychoacoustic model plays a key role in MP3).
Transform Coding
There are many other transforms besides the Fourier Transform, all with the same structure: Forward transform (general form): T (u, v ) =
M N XX x=0 y=0
Transform Coding
Other basis sets:
Walsh-Hadamard
f (x, y ) g(x, y , u, v )
Cosine
T (u, v ) h(x, y , u, v )
g(x, y, u, v ) = h(x, y , u, v ) = (u) (v ) cos where (u) = (2x + 1)u (2y + 1)v cos 2N 2N
1 N 2 N
if u = 0 otherwise
Progressive Methods
Progressive methods allow viewing of the image while downloading: Interlaced GIF:
Send every 8 scanlines, then every 4, then 2, then all Interpolate intermediate lines until they get there
8 x 8 block DCT Predictively encode DC coefcients Quantize AC coefcients Zig-zag ordering Run-length encoding Entropy encode whats left
Progressive JPEG:
Send DC coefcients rst Then send all lowest-frequency AC coefcients Then send successively higher AC coefcients
Fractals:
Blocks of the image are represented as rotated, translated, and rescaled copies of other blocks. Probably the highest claimed compression rates. Useful in some applications; very lossy in others. Some people are researching hybrid methods based on fractal compression.