Image ProcessingUnit 29 min read
Image Enhancement & Spatial Filters: Techniques, Filters & Applications
Unit 2 of Image Processing covers spatial-domain image enhancement techniques, including point operations (histogram manipulation), spatial filtering (linear/nonlinear), and their applications in real-world systems like medical imaging, surveillance, and digital photography.
Core Concepts
1. Spatial Domain vs. Frequency Domain
- Spatial domain: Direct pixel manipulation (e.g., brightness adjustment, filtering).
- Frequency domain: Uses Fourier transforms (covered in Unit 3). Here, we focus on spatial-domain methods.
2. Image Enhancement Techniques
Enhancement improves image quality for better human/machine interpretation. Two main categories:
- Point Operations: Modify pixel values independently (e.g., contrast stretching, gamma correction).
- Spatial Filtering: Apply kernels (matrices) to neighborhoods of pixels (e.g., blurring, sharpening, edge detection).
1. Point Operations
How It Works
- Each pixel’s intensity is transformed to using a function :
- No spatial interaction: Only the pixel’s own value is changed.
Key Techniques
A. Contrast Stretching (Linear Transformation)
- Goal: Expand the range of pixel intensities to use the full dynamic range (e.g., 0–255 for 8-bit images).
- Formula: where = number of gray levels (e.g., 256 for 8-bit).
- Example: Stretch a low-contrast medical X-ray to highlight bone structures.
# Pseudocode for contrast stretching I_min, I_max = min(I), max(I) I_stretched = ((I - I_min) / (I_max - I_min)) * 255
B. Gamma Correction (Nonlinear Transformation)
- Goal: Adjust brightness/contrast nonlinearly (e.g., for display calibration).
- Formula: where = scaling constant, = gamma value (: brightens dark areas; : darkens bright areas).
- Example: Correcting underexposed photos from a smartphone camera.
# Pseudocode for gamma correction (γ=0.5) I_corrected = 255 * (I / 255) ** 0.5
C. Histogram Equalization
- Goal: Redistribute pixel intensities to maximize contrast.
- Steps:
- Compute histogram (frequency of intensity ).
- Compute cumulative distribution function (CDF):
- Scale CDF to new intensity range: where = image dimensions.
- Example: Equalizing a dark indoor photo to reveal details.
flowchart LR A["Input Image"] --> B["Compute Histogram"] B --> C["Calculate CDF"] C --> D["Map to New Intensities"] D --> E["Output Enhanced Image"]
2. Spatial Filtering
How It Works
- Apply a kernel (small matrix) to each pixel’s neighborhood.
- Convolution operation: where = kernel weights.
Types of Filters
A. Linear Filters (Smoothing & Sharpening)
| Filter Type | Kernel Example (3×3) | Purpose | Example Use Case |
|---|---|---|---|
| Mean Filter | Reduce noise (blur) | Preprocessing for OCR (text recognition) | |
| Gaussian Filter | Smooth with weighted averaging | Medical imaging (removing salt-and-pepper noise) | |
| Laplacian Sharpen | Enhance edges | Satellite imagery (highlighting boundaries) | |
| Unsharp Masking | Combine original + sharpened image | Digital photography (e.g., Instagram filters) |
B. Nonlinear Filters
| Filter Type | Description | Example Use Case |
|---|---|---|
| Median Filter | Replace pixel with median of neighborhood | Remove salt-and-pepper noise |
| Max/Min Filter | Replace with max/min of neighborhood | Highlight bright/dark regions |
In the Real World
eSewa & Khalti Apps:
- Histogram equalization is used to improve receipt clarity when scanning documents for payments. Dark or unevenly lit receipts are automatically adjusted for OCR (Optical Character Recognition) to read text accurately.
NTC’s Traffic Monitoring Cameras:
- Gaussian blur filters are applied to license plates in real-time to protect privacy while Laplacian sharpening enhances pedestrian edges for accident detection.
Daraz’s Product Images:
- Unsharp masking sharpens product photos (e.g., clothes, electronics) to make details (stitching, screen pixels) visible, reducing returns due to "misleading images."
Worked Example: Noise Removal in a Medical X-Ray
Problem: A chest X-ray has Gaussian noise (random bright/dark pixels). Use a 3×3 mean filter to reduce noise while preserving edges.
Given: Original pixel neighborhood:
[120, 125, 130;
118, 122, 128;
124, 126, 132]
(Assume center pixel is noisy.)
Steps:
- Apply mean filter:
- Replace center pixel with 125.
Result: Noise is reduced, but edges (e.g., ribs) may blur slightly. For sharper results, combine with Laplacian sharpening.
Visualizing Filters
1. Kernel Application (Convolution)
How it works:
- The kernel slides over the image, computing a weighted sum for each position.
- Edge handling: Use "zero-padding," "replicate," or "wrap-around" to handle borders.
2. Effect of Filters on an Image
graph LR A["Original Image"] --> B["Mean Filter (Blurred)"] A --> C["Laplacian (Edges)"] A --> D["Median Filter (Noise-Reduced)"] B & C & D --> E["Enhanced for Analysis"]
Comparison: Linear vs. Nonlinear Filters
| Criteria | Linear Filters | Nonlinear Filters |
|---|---|---|
| Noise Handling | Smooths Gaussian noise | Better for salt-and-pepper noise |
| Edge Preservation | Blurs edges | Preserves edges better |
| Computational Cost | Low (simple arithmetic) | Higher (sorting for median) |
| Example | Mean, Gaussian, Laplacian | Median, Max/Min |
Applications in Nepal
- Nepal Police’s Biometric System:
- Median filters clean fingerprint scans before matching against databases.
- Nepal Stock Exchange (NEPSE) Screenshots:
- Histogram equalization improves readability of stock charts in low-light photos shared on social media.
- Ncell’s Tower Images:
- Gaussian blur protects privacy in surveillance footage while edge detection identifies suspicious activity.
Exam Tip
- For theoretical questions:
- Define point operations vs. spatial filtering clearly.
- Explain why histogram equalization fails for images with few intensity levels (e.g., binary images).
- For numerical problems:
- Show step-by-step convolution for a 3×3 kernel (use a 5×5 image patch for practice).
- Always state assumptions (e.g., "assuming zero-padding at borders").
- For short-answer questions:
- Match filters to noise types:
- Gaussian noise → Mean/Gaussian filter.
- Salt-and-pepper noise → Median filter.
- Know one advantage/disadvantage of each filter (e.g., mean filter blurs edges).
- Match filters to noise types:
- Practical questions:
- Given an image, describe how you’d enhance it for a specific task (e.g., "enhance a satellite image for road detection").
- Draw a kernel and explain its effect (e.g., Laplacian highlights edges).
Key Formulae to Memorize:
- Contrast stretching:
- Gamma correction:
- Convolution:
Based on the TU BIT syllabus for Image Processing, unit 2.
Discussion
Loading…