Image Processing and Pattern RecognitionUnit 313 min read
Frequency Domain Enhancement: Filters, FFT & Applications
Unit 3 of Image Processing and Pattern Recognition explores how to improve image quality by transforming images into the frequency domain, applying filters, and converting back—covering Fourier transforms, low/high-pass filtering, and real-world applications like noise removal and sharpening.
TAKEAWAYS:
- Frequency domain represents images as sums of sine/cosine waves (Fourier Transform), revealing high-frequency details (edges) and low-frequency smoothness (blurriness).
- Low-pass filters smooth images by attenuating high frequencies (e.g., Gaussian blur), while high-pass filters sharpen edges by amplifying high frequencies.
- Ideal vs. Butterworth filters balance sharpness and ringing artifacts; Butterworth’s smooth roll-off reduces Gibbs phenomenon.
- FFT (Fast Fourier Transform) efficiently computes frequency components, enabling real-time processing in apps like Instagram filters or medical imaging.
- Homomorphic filtering separates illumination/reflectance in images (e.g., correcting uneven lighting in old photos).
- Applications include noise reduction (e.g., WhatsApp photo cleanup), medical X-ray enhancement, and satellite image sharpening.
1. From Spatial to Frequency Domain: The Fourier Transform
- Low frequencies: Large, smooth regions (e.g., sky in a landscape).
- High frequencies: Edges, textures, and noise (e.g., sharp lines in a building).
How It Works
For a 2D image , the 2D Discrete Fourier Transform (DFT) is:
- : Frequency components (complex numbers).
- : Frequency coordinates (cycles per pixel).
- Magnitude spectrum : Shows energy at each frequency.
- Phase spectrum : Encodes spatial position of frequencies.
Visual: Frequency Domain Representation
Real-World Example: WhatsApp Photo Filters
- App: WhatsApp’s "Photo Filters" (e.g., "Vintage," "Clarity").
- Idea Used: High-pass filtering to enhance edges (e.g., sharpening faces) and low-pass filtering to reduce noise.
- How:
- User uploads a blurry photo.
- WhatsApp applies a high-pass filter in the frequency domain to boost high frequencies (edges).
- The filtered image is converted back to spatial domain for display.
2. Types of Frequency Domain Filters
Filters modify the magnitude spectrum to enhance or suppress certain frequencies.
A. Low-Pass Filters (LPF)
- Goal: Smooth images by removing high-frequency noise/edges.
- Types:
- Ideal LPF: Sharp cutoff (discontinuity → Gibbs ringing).
- Butterworth LPF: Smooth roll-off (reduces ringing).
- : Order (higher = sharper cutoff).
- Gaussian LPF: Exponential decay (natural smoothing).
Visual: Filter Response in Frequency Domain
Worked Example: Smoothing a Noisy Image (Ncell Photo)
Scenario: A user takes a noisy selfie with an Ncell phone. The image has salt-and-pepper noise (high-frequency spikes). Apply a Butterworth LPF to reduce noise.
Steps:
- Input: Noisy image (512×512 pixels).
- Compute DFT: Obtain .
- Apply Butterworth LPF (, ):
- .
- Multiply: .
- Inverse DFT: Convert back to spatial domain.
Result:
- Noise reduced, but edges slightly blurred.
- Trade-off: Higher = more smoothing but more blur.
B. High-Pass Filters (HPF)
- Goal: Sharpen images by enhancing edges/noise.
- Types:
- Ideal HPF: Inverts LPF (keeps high frequencies).
- Butterworth HPF:
- Unsharp Masking: Subtract blurred version from original.
- : Masking factor (typically 0.5–0.9).
Real-World Example: Instagram’s "Clarity" Filter
- App: Instagram’s "Clarity" filter.
- Idea Used: Unsharp masking in the frequency domain.
- How:
- User uploads a blurry photo.
- Instagram applies a high-pass filter (e.g., Butterworth HPF) to boost edges.
- The enhanced frequencies are added back to the original image.
- Effect: Text/edges become crisper (e.g., restaurant menus in food photos).
3. Homomorphic Filtering: Separating Illumination and Reflectance
Problem: Images often have uneven lighting (e.g., a photo taken in shade with bright sunlight). Solution: Homomorphic filtering separates:
- Illumination: Low-frequency component (lighting).
- Reflectance: High-frequency component (object details).
Steps:
- Take log: Convert multiplicative illumination into additive form.
- : Illumination.
- : Reflectance.
- Apply filter to suppress illumination:
- : High-frequency boost (e.g., 2).
- : Low-frequency attenuation (e.g., 0.5).
- Inverse log: Recover enhanced image.
Visual: Homomorphic Filtering Pipeline
flowchart LR
A["Original Image\n(f(x,y))"] --> B["Log Transformation\nz = log(f)"]
B --> C["Frequency Domain\nZ(u,v)"]
C --> D["Apply Homomorphic Filter\nH(u,v)"]
D --> E["Inverse DFT\nz'(u,v)"]
E --> F["Exponential\nf'(x,y) = e^{z'}"]
F --> G["Enhanced Image"]Worked Example: Correcting a Daraz Product Photo
Scenario: A Daraz seller uploads a product photo with uneven lighting (left side dark, right side bright). Use homomorphic filtering to normalize lighting.
Steps:
- Input: Product image (e.g., a phone).
- Log transform: .
- Compute DFT: .
- Apply homomorphic filter:
- , , , .
- Inverse DFT: .
- Exponential: .
Result:
- Illumination evens out; product details (reflectance) remain sharp.
4. Comparison of Filters
| Filter Type | Purpose | Advantages | Disadvantages | Example Use Case |
|---|---|---|---|---|
| Ideal LPF | Noise removal | Simple to implement | Gibbs ringing (artifacts) | Basic noise reduction |
| Butterworth LPF | Smooth noise removal | No ringing, adjustable cutoff | Computationally intensive for high | Medical imaging (X-rays) |
| Gaussian LPF | Natural smoothing | No ringing, smooth transition | Less aggressive than Butterworth | Face blurring (privacy apps) |
| Ideal HPF | Edge enhancement | Boosts high frequencies | Amplifies noise | Sharpening text (OCR apps) |
| Unsharp Masking | Sharpening | Preserves details | Over-sharpening if too high | Photo retouching (Photoshop) |
| Homomorphic | Illumination correction | Separates lighting/reflectance | Complex math, sensitive to parameters | Restoring old photos (eSewa archives) |
5. Fast Fourier Transform (FFT): Why It Matters
The DFT is computationally expensive ( for images). The FFT reduces this to using:
- Divide-and-conquer: Split the image into even/odd rows/columns.
- Recursive computation: Reuse overlapping calculations.
Real-World Example: YouTube’s Video Compression
- App: YouTube’s video encoding.
- Idea Used: FFT-based compression (e.g., H.264 codec).
- How:
- Videos are divided into frames.
- Each frame undergoes DCT (Discrete Cosine Transform), a Fourier-like transform.
- FFT accelerates the DCT computation, reducing file size by discarding low-energy frequencies.
- Result: Faster uploads/streaming (e.g., 4K videos on slow NTC connections).
6. Practical Implementation Steps
To apply frequency-domain filtering in Python (using numpy and scipy):
import numpy as np
import cv2
from scipy.fftpack import fft2, ifft2, fftshift
# Load image
img = cv2.imread('noisy_image.jpg', 0) # Grayscale
# Compute FFT
f_img = fft2(img)
f_shift = fftshift(f_img) # Center low frequencies
# Create Butterworth LPF mask
rows, cols = img.shape
crow, ccol = rows // 2, cols // 2
D0 = 30
mask = np.zeros((rows, cols))
for u in range(rows):
for v in range(cols):
D = np.sqrt((u - crow)**2 + (v - ccol)**2)
mask[u,v] = 1 / (1 + (D / D0)**4)
# Apply filter
f_filtered = f_shift * mask
filtered_img = np.abs(ifft2(fftshift(f_filtered)))
# Display
cv2.imshow('Filtered', filtered_img)
cv2.waitKey(0)
Output Visualization
Exam Tip
- Understand the DFT/FFT relationship: Know that FFT is an efficient way to compute DFT, but DFT is the mathematical foundation.
- Filter design: For LPF/HPF questions, sketch the magnitude response and explain the trade-offs (e.g., Butterworth vs. Ideal).
- Homomorphic filtering: Memorize the log/exponential steps and the purpose of and .
- Applications: Relate filters to real-world scenarios:
- LPF: Noise removal in medical images (e.g., NTC’s ultrasound scans).
- HPF: Sharpening satellite images (e.g., NASA’s Earth observation).
- Homomorphic: Restoring old photos (e.g., eSewa’s digitized archives).
- Common pitfalls:
- Forgetting to center the frequency spectrum (
fftshift) before filtering. - Misapplying the inverse transform (use
ifft2, notfft2). - Ignoring the phase spectrum (always keep it unchanged unless specified).
- Forgetting to center the frequency spectrum (
In the Real World
eSewa’s Document Scanning
- Idea: Homomorphic filtering to correct uneven lighting in scanned documents (e.g., voter ID photos).
- How: The app applies a homomorphic filter to separate illumination (e.g., glare from a window) from text (reflectance), ensuring OCR accuracy.
Pathao’s Driver App
- Idea: High-pass filtering to enhance license plate numbers in low-light photos (e.g., verifying driver licenses).
- How: When a driver uploads a blurry license plate, Pathao’s backend applies an unsharp mask to sharpen edges before OCR processing.
Nepal Rastra Bank’s Currency Detection
- Idea: Frequency-domain analysis to detect counterfeit notes.
- How: Genuine notes have unique high-frequency textures (e.g., microprinting). Banks use HPFs to isolate these textures and compare them to a database.
Daraz’s Product Image Pipeline
- Idea: Butterworth LPF to reduce noise in product photos before listing.
- Example: A seller uploads a noisy photo of a phone. Daraz’s system applies a Butterworth LPF (, ) to smooth the background while preserving the phone’s details.
Key Formulas to Memorize
| Concept | Formula |
|---|---|
| 2D DFT | |
| Butterworth LPF | |
| Homomorphic Filter | (for ) |
| Unsharp Masking |
Summary of Steps for Frequency-Domain Enhancement
flowchart TD
A["Original Image\nSpatial Domain"] --> B["Compute DFT\nF(u,v)"]
B --> C["Apply Filter\nH(u,v)"]
C --> D["Inverse DFT\nf'(x,y)"]
D --> E["Enhanced Image"]
C -->|"Branch"| F["Homomorphic:\nLog → Filter → Exp"]
F --> EFinal Checklist for Exams
- Can you sketch the magnitude spectrum of an image and label low/high frequencies?
- For a given filter (e.g., Butterworth LPF), can you write its equation and explain its parameters?
- In a homomorphic filtering question, can you derive the steps from log to exponential?
- For a real-world scenario (e.g., WhatsApp filters), can you map the problem to a filter type and justify your choice?
Based on the PU BE Computer (PU) syllabus for Image Processing and Pattern Recognition (CMP362), unit 3.
Discussion
Loading…