Image ProcessingUnit 38 min read
Image Enhancement in Spatial Domain: Filters, Histograms & Contrast
Unit 3 of Image Processing: Learn how to improve image quality by adjusting pixel intensities directly (spatial domain), including histogram equalization, point operations, neighborhood filters, and noise reduction—with step-by-step examples and real-world ties to eSewa’s receipt clarity and Daraz’s product photos.
TAKEAWAYS:
- Spatial domain enhances images by modifying pixel values directly (e.g., contrast stretching, histogram equalization).
- Point operations (e.g., negative, log, power-law) alter pixel values independently of neighbors.
- Neighborhood filters (e.g., averaging, median) smooth noise or sharpen edges using local pixel groups.
- Histogram equalization flattens pixel distributions to improve contrast, critical for low-light Daraz product shots.
- Noise models (Gaussian, salt-and-pepper) guide restoration; spatial filters like Wiener can recover degraded images.
- Real-world use: eSewa’s receipts use histogram equalization to ensure readability; Pathao’s GPS images rely on edge-preserving filters.
1. Spatial Domain vs. Frequency Domain
Spatial domain processing operates directly on pixel values (intensity, color) in the image matrix. Unlike frequency domain methods (e.g., Fourier transforms), it does not convert the image into frequency components. This makes spatial techniques intuitive but computationally heavier for large images.
flowchart TD
A["Spatial Domain"] -->|"Pixel-wise"| B["Histogram Equalization"]
A -->|"Local operations"| C["Neighborhood Filters"]
A -->|"Point operations"| D["Contrast Stretching"]
A -->|"Noise removal"| E["Median Filter"]
F["Frequency Domain"] -->|"Frequency components"| G["Fourier Transform"]
F -->|"Frequency filtering"| H["Low-pass Filters"]Key difference:
| Aspect | Spatial Domain | Frequency Domain |
|---|---|---|
| Representation | Pixel intensities (I(x,y)) | Frequency components (F(u,v)) |
| Operations | Direct pixel manipulation | Filtering in frequency space |
| Speed | Slower for large images | Faster for repetitive patterns |
| Example | Histogram equalization | Blurring with a Gaussian mask |
2. Point Operations: Pixel-by-Pixel Transformations
Point operations apply a function to each pixel independently, ignoring its neighbors. Common transformations include:
- Negative (Inversion): (reverses brightness).
- Logarithmic: (compresses highlights).
- Power-law (Gamma correction): (adjusts contrast).
Example: Darkening a Daraz product photo for better visibility. Worked Example: Convert a pixel value using .
- Apply power-law: .
- Clamp to [0, 255]: .
Advantages:
- Simple to implement.
- Preserves spatial relationships (no blurring).
Disadvantages:
- Cannot remove noise or enhance edges without neighbor info.
3. Histogram Processing: Contrast Stretching & Equalization
Histograms show pixel intensity distributions. Enhancing contrast involves reshaping this distribution.
A. Histogram Equalization
Flattens the histogram to maximize contrast by redistributing pixel intensities. Used in eSewa receipts to ensure text remains legible under varying lighting.
Steps:
- Compute cumulative distribution function (CDF).
- Map CDF to new intensity values .
Worked Example: Given histogram (from past exam):
| Gray Level | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Frequency | 0 | 25 | 0 | 10 | 35 | 50 | 0 | 0 |
Normalize frequencies: . , , etc.
Compute CDF: . , .
Map to new intensities: , where . (rounded).
Resulting histogram: More uniform distribution → higher contrast.
B. Histogram Specifying
Replace the original histogram with a desired shape (e.g., Gaussian) for artistic effects.
Example: Darkening a Pathao GPS image to reduce glare:
flowchart TD
A["Original Histogram"] --> B["Target Gaussian Histogram"]
B --> C["Compute CDF Mapping"]
C --> D["Apply to Pixels"]4. Neighborhood Operations: Local Filters
Process pixels based on local neighborhoods (e.g., 3×3 kernel). Key filters:
- Averaging (Blurring): Smooths noise. .
- Median: Removes salt-and-pepper noise. .
- Sharpening: Highlights edges (e.g., Laplacian).
Example: Blurring a noisy Ncell network image. Worked Example: Blur a 3×3 pixel block:
Original:
[100 102 101]
[98 100 99 ]
[103 101 102]
- Sum all pixels: .
- Divide by 9: .
Advantages:
- Smooths noise (median filter).
- Preserves edges better than global operations.
Disadvantages:
- Blurring reduces sharpness.
- Computationally intensive for large kernels.
5. Noise Models and Restoration
Noise degrades images; spatial filters restore them. Common noise types:
- Gaussian: Smooth, random variations (e.g., sensor noise).
- Salt-and-pepper: Random black/white pixels (e.g., corrupted Daraz thumbnails).
- Speckle: Multiplicative noise (e.g., medical ultrasound).
Restoration Process:
- Model degradation: , where:
- : Degraded image.
- : Point spread function (PSF).
- : Original image.
- : Noise.
- Inverse filtering: Estimate from .
- Spatial filters: Wiener filter, median filter.
Example: Restoring a blurry NEPSE stock chart.
flowchart TD
A["Degraded Image"] --> B["Estimate PSF"]
B --> C["Apply Wiener Filter"]
C --> D["Restored Image"]6. Edge-Preserving Filters
Filters that smooth noise without blurring edges:
- Bilateral filter: Combines spatial and intensity proximity.
- Anisotropic diffusion: Smooths in directions perpendicular to edges.
Example: Enhancing Kathmandu traffic routes in satellite images.
In the Real World
eSewa Receipts:
- Idea: Histogram equalization ensures text remains readable under varying lighting conditions in receipts.
- How: The app applies adaptive contrast stretching to compensate for low-light scans or printed receipts.
Daraz Product Photos:
- Idea: Gamma correction (power-law) adjusts exposure for product images shot in different lighting.
- How: Darker images are brightened slightly to match the platform’s standard contrast.
Pathao GPS Navigation:
- Idea: Median filtering removes salt-and-pepper noise from real-time GPS data to smooth route updates.
- Worked Example:
Suppose a GPS sensor reports noisy coordinates:
A median filter (window size 3) would average the middle values to reduce outliers.(5.76°, 85.31°), (5.75°, 85.30°), (5.77°, 85.32°), (5.74°, 85.29°)
Exam Tip
- Focus on:
- Histogram equalization: Always show CDF mapping steps (like in the worked example).
- Filter kernels: Draw 3×3 matrices for averaging/median/Laplacian.
- Noise models: Link Gaussian/salt-and-pepper noise to real-world examples (e.g., Ncell signal interference).
- Common pitfalls:
- Forgetting to clamp pixel values to [0, 255] after transformations.
- Mixing up point operations (single pixel) with neighborhood operations (local kernel).
- Past exam patterns:
- 20%: Define terms (e.g., "neighborhood filter").
- 30%: Compute histogram equalization or filter outputs (show all steps).
- 25%: Compare spatial vs. frequency domain (table format).
- 25%: Apply filters to small matrices (e.g., 3×3 averaging).
Visual Summary:
mindmap
root((Image Enhancement))
Spatial Domain
Point Operations
Negative|Log|Gamma
Histogram
Equalization|Specifying
Neighborhood
Averaging|Median|Sharpening
Real-World Tie
eSewa|Daraz|PathaoBased on the TU BSc CSIT syllabus for Image Processing (CSC332), unit 3.
Discussion
Loading…