Chapter 8: Image Compression
Notes based on Digital Image Processing by Rafael C. Gonzalez and Richard E. Woo
August 3, 2025
Overview
Chapter 8 explores image compression, techniques to reduce the size of image data while
preserving quality for storage or transmission. It covers fundamentals of data compres-
sion, lossless and lossy compression methods, and standards like JPEG and JPEG2000.
The chapter emphasizes the trade-off between compression ratio and image quality, with
practical examples using MATLAB.
1 Key Concepts
1.1 Fundamentals of Image Compression
• Definition: Image compression reduces the amount of data required to represent
an image.
• Compression Ratio: Ratio of original to compressed data size:
Original Size
Compression Ratio =
Compressed Size
• Types:
– Lossless: No data loss, exact reconstruction (e.g., PNG, ZIP).
– Lossy: Some data loss, acceptable for visual quality (e.g., JPEG).
• Redundancy: Compression exploits:
– Coding Redundancy: Inefficient representation of pixel values.
– Spatial Redundancy: Correlation between neighboring pixels.
– Psychovisual Redundancy: Human vision’s insensitivity to certain details.
1.2 Information Theory Basics
• Entropy: Measures the information content of an image:
∑
L−1
H=− p(ri ) log2 p(ri )
i=0
where p(ri ) is the probability of intensity level ri , and L is the number of intensity
levels.
1
• Coding Efficiency: Compression aims to represent data with bits close to the
entropy.
1.3 Lossless Compression Techniques
• Huffman Coding: Assigns shorter codes to frequent pixel values, optimal for
grayscale images.
• Run-Length Encoding (RLE): Encodes sequences of identical pixels (e.g., in
binary images).
• Lempel-Ziv-Welch (LZW): Builds a dictionary of repeating patterns, used in
GIF, TIFF.
• Arithmetic Coding: Encodes data as a fractional number, more efficient than
Huffman but complex.
1.4 Lossy Compression Techniques
• Transform Coding: Transforms image to a domain (e.g., frequency) where data
is more compressible.
– Discrete Cosine Transform (DCT): Basis for JPEG, compacts energy into few
coefficients.
– Wavelet Transform: Basis for JPEG2000, better for high-frequency details
(Chapter 7).
• Quantization: Reduces precision of transform coefficients, introducing loss.
• Predictive Coding: Predicts pixel values based on neighbors, encodes differences
(e.g., DPCM).
1.5 JPEG Compression Standard
• Process:
1. Divide image into 8x8 blocks.
2. Apply DCT to each block to get frequency coefficients.
3. Quantize coefficients using a quantization table (lossy step).
4. Encode quantized coefficients using Huffman coding (lossless).
• Artifacts: Blocking artifacts at high compression ratios due to 8x8 block process-
ing.
2
1.6 JPEG2000 Compression Standard
• Process: Uses wavelet transform (e.g., Daubechies) instead of DCT.
1. Apply DWT to decompose image into subbands.
2. Quantize wavelet coefficients.
3. Encode using arithmetic coding or EBCOT (Embedded Block Coding with
Optimized Truncation).
• Advantages: Better quality at high compression, no blocking artifacts, supports
lossless mode.
1.7 Error Metrics
• Mean Square Error (MSE):
1 ∑∑
M −1 N −1
MSE = [f (x, y) − fˆ(x, y)]2
M N x=0 y=0
where f (x, y) is the original image, fˆ(x, y) is the compressed image.
• Peak Signal-to-Noise Ratio (PSNR):
( )
L2
PSNR = 10 log10
MSE
where L is the maximum intensity (e.g., 255 for 8-bit images).
1.8 Practical Implementation
• MATLAB supports compression via imwrite (e.g., JPEG) and Wavelet Toolbox
for JPEG2000.
• Example: Compressing an image with JPEG in MATLAB:
img = imread('image.png');
imwrite(img, 'compressed.jpg', 'Quality', 50); % JPEG with quality factor 50
compressed_img = imread('compressed.jpg');
imshow(compressed_img);
2 Simple Notes
• Image Compression: Reduces data size for storage/transmission.
• Types:
– Lossless: No data loss (e.g., PNG).
– Lossy: Some loss, good visual quality (e.g., JPEG).
3
• Redundancy:
– Coding: Inefficient pixel representation.
– Spatial: Neighboring pixel correlation.
– Psychovisual: Human vision ignores some details.
• Lossless Methods:
– Huffman: Short codes for frequent values.
– RLE: Encodes repeated pixels.
– LZW : Dictionary-based, for GIF/TIFF.
• Lossy Methods:
– DCT: Used in JPEG, compacts energy.
– Wavelet: Used in JPEG2000, better quality.
– Quantization: Reduces coefficient precision.
• JPEG: DCT, 8x8 blocks, quantization, Huffman coding.
• JPEG2000: Wavelet transform, no blocking, better quality.
• Metrics: MSE, PSNR measure compression quality.
• Tools: MATLAB (imwrite, Wavelet Toolbox) for compression.
3 Key Takeaways
• Image compression reduces data by exploiting redundancies.
• Lossless methods preserve all data; lossy methods trade quality for size.
• JPEG uses DCT; JPEG2000 uses wavelets for better quality.
• Compression quality is evaluated using MSE and PSNR.
• MATLAB facilitates compression and quality assessment.
4 Study Tips
• Visualize: Study book figures for DCT coefficients and compression artifacts.
• Practice: Use MATLAB to compress images with JPEG/JPEG2000 and compare
quality.
• Math: Review entropy, DCT, and wavelet equations.
• Experiment: Test different quality factors in JPEG or wavelet levels in JPEG2000.
4
5 Additional Notes
• The 4th edition includes MATLAB projects at www.ImageProcessingPlace.com.
• Chapter 8 builds on Chapter 7 (wavelets) and Chapter 4 (frequency domain).
• Later chapters (e.g., feature extraction) may use compressed images.