CMP362 Image Processing and Pattern Recognition

Image Processing and Pattern RecognitionUnit 28 min read

Image Enhancement in Spatial Domain: Techniques, Filters & Applications

Unit 2 of Image Processing and Pattern Recognition explores spatial-domain enhancement methods—point operations, spatial filtering, and morphological processing—to improve image quality, contrast, and features for better analysis and recognition.

Core Concepts

1. Spatial Domain vs. Frequency Domain

  • Spatial domain: Direct manipulation of pixel intensities in the image (e.g., brightness, contrast).
  • Frequency domain: Manipulation of image frequencies (Fourier transform) to enhance edges or remove noise.
  • Key difference: Spatial methods work on pixel values; frequency methods work on transformed data.
ImageSpatial DomainFrequency DomainPoint OperationsSpatial FilteringMorphologicalFrequency Filtering
Flowchart showing the two domains of image enhancement and their sub-techniques

2. Point Operations (Intensity Transformations)

5010015020025050100150200250xyLinear Transformation (y = x/10)Non-linear (Gamma Correction)(0, 0)(255, 255)
Example of intensity transformation functions for contrast stretching

Definitions & Types

  • Point operation: Modifies pixel values based on its own intensity (no neighbor dependency).
  • Common operations:
    • Linear: (e.g., contrast stretching).
    • Nonlinear: Logarithmic, power-law (gamma correction), histogram equalization.

How It Works

  • Input: Original image with intensity .
  • Output: Transformed image .
  • Example: Dark image → contrast stretching to use full dynamic range.

Worked Example: Contrast St stretching

Given:

  • Original image: 8-bit grayscale (0–255).
  • Input range: , .
  • Output range: 0–255.

Formula: where (for 8-bit).

Steps:

  1. For : .
  2. For : .
  3. For :

Visualization:


Advantages:

  • Simple, fast (no neighbor computation).
  • Preserves spatial relationships.

Disadvantages:

  • Limited to global changes (no local adaptability).

3. Spatial Filtering (Neighborhood Operations)

Definitions

  • Spatial filter: Modifies pixel values based on a kernel/mask (e.g., 3×3, 5×5).
  • Types:
    • Linear filters: Weighted average (e.g., mean, Gaussian blur).
    • Nonlinear filters: Median filter (noise removal), max/min filters.

How It Works

  1. Kernel placement: Center the kernel over each pixel.
  2. Convolution: Multiply kernel weights by pixel values, sum results.
  3. Normalization: Divide by sum of kernel weights (for linear filters).

Worked Example: Mean Filter (Blurring)

Given:

  • Image pixel values (3×3 neighborhood):
    [100 120 150]
    [110 130 140]
    [160 170 180]
    
  • Kernel (3×3 mean filter):
100,120,1500110,130,1601120,140,1702
3×3 pixel neighborhood for mean filter calculation (center pixel = 130)

Calculation for center pixel (130):

Visualization:


Advantages:

  • Reduces noise (smoothing).
  • Preserves edges poorly (blurring effect).

Disadvantages:

  • Blurs edges and fine details.
  • Slow for large kernels.

4. Morphological Operations

Definitions

  • Morphology: Shapes image based on structuring elements (e.g., disk, square).
  • Operations:
    • Erosion: Shrinks bright regions (removes small white noise).
    • Dilation: Expands bright regions (fills gaps).
    • Opening: Erosion → Dilation (removes small objects).
    • Closing: Dilation → Erosion (fills small holes).

How It Works

  1. Erosion: Replace pixel with min of neighborhood (under structuring element).
  2. Dilation: Replace pixel with max of neighborhood.

Worked Example: Erosion with Disk Structuring Element

Given:

  • Binary image (1 = object, 0 = background):
    [1 1 0]
    [1 0 0]
    [0 0 0]
    
  • Structuring element (3×3 disk):
    [0 1 0]
    [1 1 1]
    [0 1 0]
    

Erosion of center pixel (0):

  • Overlay structuring element → all 8 neighbors must be 1 (not true here).
  • Result: Center becomes 0 (unchanged, but edges shrink).

Visualization:


Advantages:

  • Preserves shape while removing noise.
  • Useful for segmentation.

Disadvantages:

  • Over-erosion can disconnect objects.
  • Sensitive to structuring element size.

5. Applications in Real World

1. Medical Imaging (e.g., NAMS Hospital, Nepal)

  • Use case: Enhancing X-ray images for better diagnosis.
  • Technique: Histogram equalization to improve contrast in low-light X-rays.
  • Impact: Helps radiologists detect fractures or tumors earlier.

2. Surveillance Systems (e.g., NTC Traffic Cameras)

  • Use case: License plate recognition in poor lighting.
  • Technique: Adaptive histogram equalization (AHE) to enhance plate visibility.
  • Impact: Reduces false negatives in automated toll systems.

3. Agriculture (e.g., Daraz Farm Products)

  • Use case: Detecting pests in crop images.
  • Technique: Median filtering to remove noise from drone-captured images.
  • Impact: Early pest detection → higher yield.

4. Social Media (e.g., Facebook Filters)

  • Use case: Beauty filters (e.g., "Smooth Skin").
  • Technique: Gaussian blur + edge-preserving filters.
  • Impact: Millions of daily users rely on spatial filtering for aesthetic enhancement.

6. Comparison Table: Enhancement Techniques

Technique Domain Key Use Case Pros Cons
Contrast Stretching Spatial Improve low-contrast images Fast, simple Global changes only
Mean Filter Spatial Noise reduction Smooths noise Blurs edges
Median Filter Spatial Salt-and-pepper noise removal Preserves edges Slower than mean filter
Erosion Morphological Remove small objects Shape-preserving Over-erosion risks
Histogram Equalization Spatial Enhance contrast globally Adaptive to image content May over-amplify noise

7. Exam Tip

What Examiners Look For

  1. Definitions: Clearly distinguish between point operations, spatial filtering, and morphology.
  2. Mathematical Steps: Show full calculations for kernel applications (e.g., mean filter).
  3. Visual Proof: Always draw before/after for contrast stretching or filtering.
  4. Applications: Link techniques to real-world problems (e.g., medical imaging, surveillance).
  5. Trade-offs: Discuss when to use linear vs. nonlinear filters (e.g., median for impulse noise).

Common Pitfalls

  • Assuming all filters are interchangeable: Mean filter ≠ median filter!
  • Ignoring kernel size: Larger kernels blur more but take longer.
  • Forgetting normalization: Always divide by kernel sum for linear filters.

Sample Exam Question & Answer

Q: Explain how a 3×3 mean filter works. Apply it to a 3×3 neighborhood with pixels:

[50 60 70]
[80 90 100]
[110 120 130]

A:

  1. Kernel: All weights = .
  2. Calculation for center (90): (Note: Center remains unchanged in this symmetric case.)
  3. Edge pixels: Use partial kernel (e.g., top-left pixel = average of its 3 neighbors).

Based on the PU BE Computer (PU) syllabus for Image Processing and Pattern Recognition (CMP362), unit 2.

Discussion

Loading…