Image ProcessingUnit 35 min read
Image Restoration & Compression: Noise Removal, Deconvolution, JPEG, DCT, Huffman
Unit 3 of Image Processing covers techniques to reverse image degradation (restoration) and reduce file size (compression), including noise filtering, deblurring, transform coding (DCT), and entropy coding (Huffman). Learn how to mathematically recover lost details and compress images efficiently for web and storage.
What is Image Restoration?
Types of Degradation
- Noise: Random variations in pixel intensity (e.g., salt-and-pepper, Gaussian).
- Blur: Loss of sharpness due to motion, defocus, or camera shake.
- Sensor Defects: Dead pixels or stuck bits in the camera sensor.
Restoration Techniques
1. Noise Removal
Goal: Reduce random noise while preserving edges. Methods:
- Linear Filtering: Average/smoothing filters (e.g., mean filter).
- Nonlinear Filtering: Median filter (better for salt-and-pepper noise).
- Wiener Filter: Optimal for Gaussian noise (uses statistical properties).
2. Deblurring (Inverse Filtering)
Goal: Reverse blur caused by a known point-spread function (PSF). Steps:
- Model blur as a convolution: , where:
- : degraded image,
- : original image,
- : PSF (blur kernel),
- : noise.
- Apply inverse filtering in frequency domain:
- Problem: Noise amplification if has near-zero values. Solution: Wiener deconvolution (regularization).
3. Geometric Distortion Correction
Goal: Fix distortions from lens or sensor misalignment. Methods:
- Affine Transformations: Correct perspective or skew.
- Homography: Map distorted image to a reference plane (used in satellite imagery).
graph LR
A["Degraded Image"] -->|"Noise"| B["Noise Removal"]
A -->|"Blur"| C["Deblurring"]
A -->|"Distortion"| D["Geometric Correction"]
B -->|"Filtering"| E["Restored Image"]
C -->|"Inverse Filter"| E
D -->|"Transformation"| EExample: Restoring a blurry photo from a shaky phone camera. Assume a 3×3 blur kernel:
[0.11 0.11 0.11]
[0.11 0.11 0.11]
[0.11 0.11 0.11]
Apply inverse filtering in the frequency domain to recover sharp edges.
Image Compression
Compression reduces file size while minimizing quality loss. Two main types:
- Lossless: No data loss (e.g., ZIP, PNG). Used for medical/scientific images.
- Lossy: Sacrifices quality for higher compression (e.g., JPEG, MP3). Used for photos/videos.
Key Techniques
1. Transform Coding (DCT)
Goal: Convert spatial redundancy into frequency coefficients. Steps:
- Divide image into 8×8 blocks.
- Apply Discrete Cosine Transform (DCT): where if , else 1.
- Quantize high-frequency coefficients (small values → zero).
- Encode remaining coefficients (e.g., zigzag scan).
Visual: Note: Low-frequency coefficients (top-left) carry most energy.
2. Entropy Coding (Huffman)
Goal: Assign shorter codes to frequent symbols. Steps:
- Calculate symbol probabilities (e.g., DCT coefficient frequencies).
- Build Huffman tree:
- Combine least frequent symbols iteratively.
- Assign binary codes (e.g.,
0for frequent,10for rare).
- Encode image data using the Huffman table.
Example:
| Symbol | Probability | Huffman Code |
|---|---|---|
| 0 | 0.4 | 0 |
| 1 | 0.3 | 10 |
| 2 | 0.2 | 110 |
| 3 | 0.1 | 111 |
Compression Ratio:
JPEG Compression Pipeline
flowchart LR
A["Original Image"] --> B["Divide into 8×8 Blocks"]
B --> C["DCT Transform"]
C --> D["Quantization"]
D --> E["Zigzag Scan"]
E --> F["Huffman Encoding"]
F --> G["Compressed JPEG"]Real-World Example:
- Daraz/Flipkart Product Images: Compressed with JPEG to load faster on mobile networks.
- WhatsApp Media: Uses JPEG for photos and Huffman-like encoding for metadata.
In the Real World
- eSewa/NTT Data: Compress transaction receipts (JPEG) to reduce server storage.
- Pathao Driver App: Uses image compression to send real-time traffic snapshots to the backend.
- NEPSE Stock Charts: Apply noise removal to clean up low-light stock photos before analysis.
Worked Example: Compressing a 512×512 grayscale image (262,144 pixels × 8 bits = 2.1 MB).
- Divide into 8×8 blocks → 4,096 blocks.
- Apply DCT → Quantize high frequencies (e.g., discard coefficients < 5).
- Huffman encode → Assume 50% reduction → Final size: ~1.05 MB (50% compression).
Exam Tip
- Restoration:
- Know the inverse filtering equation and its limitations (noise amplification).
- Compare Wiener filter vs. median filter (Wiener for Gaussian noise, median for salt-and-pepper).
- Compression:
- Memorize DCT steps and the zigzag scan pattern.
- Calculate compression ratio for Huffman tables.
- Applications:
- Link JPEG to web images, PNG to logos, and lossless to medical imaging.
- Math Shortcuts:
- For DCT, focus on the energy compaction property (most energy in low frequencies).
- For Huffman, practice building trees from probability tables.
Based on the TU BIT syllabus for Image Processing, unit 3.
Discussion
Loading…