Compression

Compression reduces the volume of data required to represent an image, without necessarily reducing its information content. It works by removing data redundancy.

  • Lossless compression
    Source and reconstructed image match pixel to pixel.
  • Lossy compression
    Source and reconstructed image may not match pixel to pixel.

Compression Ratio

For the same information encoded with n1n_1 units of data under scheme C1C_1 and n2n_2 units under scheme C2C_2:

CR=n1n2CR = \frac{n_1}{n_2}

Relative data redundancy of C2C_2 compared to C1C_1:

RD=1−1CRRD = 1 - \frac{1}{CR}
  • CR>1CR > 1 means C2C_2 compresses relative to C1C_1
  • CR=1CR = 1 means RD=0RD = 0 and no redundancy is removed
  • CR<1CR < 1 means RD<0RD < 0 and C2C_2 expands the data

For an M×NM \times N image coded in bb bits:

bpp=bMNCR=b1b2=bpp1bpp2\text{bpp} = \frac{b}{MN} \qquad CR = \frac{b_1}{b_2} = \frac{\text{bpp}_1}{\text{bpp}_2}

For example, CR=10CR = 10 gives RD=0.9RD = 0.9, so 90% of the original data is redundant.

Reconstruction Error

A lossy scheme reconstructs f^(x,y)\hat{f}(x,y) from the original f(x,y)f(x,y). The error measures below compare the 2 images.

e(x,y)=f^(x,y)−f(x,y)MSE=1MN∑x=0M−1∑y=0N−1e(x,y)2erms=MSEPSNR=10log⁡10MAX2MSE dB\begin{align} e(x,y) &= \hat{f}(x,y) - f(x,y) \\ \text{MSE} &= \frac{1}{MN} \sum_{x=0}^{M-1} \sum_{y=0}^{N-1} e(x,y)^2 \\ e_\text{rms} &= \sqrt{\text{MSE}} \\ \text{PSNR} &= 10 \log_{10} \frac{\text{MAX}^2}{\text{MSE}} \text{ dB} \end{align}

A lossless scheme has e(x,y)=0e(x,y) = 0 for every pixel. See image quality assessment for PSNR and SSIM.

Compression Pipeline

A compression system has an encoder and a decoder. The encoder is a chain of 4 stages. Each stage targets 1 kind of redundancy.

Mapper→Quantizer→Symbol encoder→Channel encoder\text{Mapper} \to \text{Quantizer} \to \text{Symbol encoder} \to \text{Channel encoder}

Decompression runs the inverse of each stage in reverse order. The quantizer has no inverse, so a pipeline containing it is lossy.

Mapper

Transforms the pixel array into a representation where interpixel redundancy is exposed. The mapping is reversible and loses no information.

Examples:

  • Run-length encoding, which replaces a run of equal pixels by the pixel value and the run length
  • Predictive coding, which stores the difference between each pixel and its prediction from neighbours
  • Transform coding, which stores coefficients of a transform such as the DCT

Quantizer

Reduces the number of distinct values the mapper output can take, so fewer bits per value are needed. It removes psychovisual redundancy by discarding detail the eye barely perceives.

  • Irreversible, so it is the only stage that makes the pipeline lossy
  • Optional, and omitted in lossless compression
  • Coarser quantization gives a higher CRCR and a lower reconstruction quality

A uniform quantizer with step Δ\Delta is:

v^=Δ⋅round(vΔ)∣v−v^∣≤Δ2\hat{v} = \Delta \cdot \text{round}\left(\frac{v}{\Delta}\right) \qquad |v - \hat{v}| \le \frac{\Delta}{2}

With the error spread evenly over the step, the mean squared error is:

MSE=Δ212\text{MSE} = \frac{\Delta^2}{12}

Symbol Encoder

Assigns a code to each quantized value. Short codes go to frequent values and long codes to rare values. It removes coding redundancy.

  • Reversible
  • The average code length approaches the entropy of the source
Bavg≤Lavg<Bavg+1B_\text{avg} \le L_\text{avg} < B_\text{avg} + 1

Examples:

  • Huffman coding
  • Arithmetic coding
  • LZW coding

Channel Encoder

Adds controlled redundancy to the compressed bitstream. The decoder uses it to detect and correct errors from storage or transmission, since a compressed stream has little natural redundancy left to survive a bit error.

A code that turns kk data bits into nn transmitted bits has:

Rc=knoverhead=n−kkR_c = \frac{k}{n} \qquad \text{overhead} = \frac{n - k}{k}

Examples:

  • Parity bit, with n=k+1n = k + 1
  • Hamming code, such as (n,k)=(7,4)(n, k) = (7, 4) with Rc=47R_c = \frac{4}{7}

Worked Example

Uniform Quantization

A mapper coefficient is v=27v = 27. A uniform quantizer has Δ=8\Delta = 8. Find the reconstructed coefficient and its squared error.

Solution Reveal Hide
v^=8⋅round⁡(278)=8⋅3=24\hat{v} = 8 \cdot \operatorname{round}\left(\frac{27}{8}\right) = 8 \cdot 3 = 24(v−v^)2=(27−24)2=9(v - \hat{v})^2 = (27 - 24)^2 = 9

The quantizer reconstructs 2424 with squared error 99.

Written by October 28, 2026 3 min read
Was this helpful?