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:

  1. Point Operations: Modify pixel values independently (e.g., contrast stretching, gamma correction).
  2. Spatial Filtering: Apply kernels (matrices) to neighborhoods of pixels (e.g., blurring, sharpening, edge detection).

1. Point Operations

0.10.20.30.40.50.60.70.80.910.20.40.60.81xyLinear (Contrast Stretching)Gamma Correction (γ=2.5)Gamma Correction (γ=0.5)Input: 0.2Input: 0.8
Pixel intensity transformation curves for point operations (0–1 range)

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:
    1. Compute histogram (frequency of intensity ).
    2. Compute cumulative distribution function (CDF):
    3. 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

  1. 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.
  2. 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.
  3. 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.

128,130,127,1320129,125,126,1311133,124,128,1302127,131,129,1263
4×4 pixel patch before/after median filtering (noise spike at (2,2) removed)

Given: Original pixel neighborhood:

[120, 125, 130;
 118, 122, 128;
 124, 126, 132]

(Assume center pixel is noisy.)

Steps:

  1. Apply mean filter:
  2. 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

  1. Nepal Police’s Biometric System:
    • Median filters clean fingerprint scans before matching against databases.
  2. Nepal Stock Exchange (NEPSE) Screenshots:
    • Histogram equalization improves readability of stock charts in low-light photos shared on social media.
  3. Ncell’s Tower Images:
    • Gaussian blur protects privacy in surveillance footage while edge detection identifies suspicious activity.

Exam Tip

  1. 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).
  2. 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").
  3. 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).
  4. 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:

  1. Contrast stretching:
  2. Gamma correction:
  3. Convolution:

Based on the TU BIT syllabus for Image Processing, unit 2.

Discussion

Loading…