Image ProcessingUnit 117 min read
Edge Detection & Feature Extraction: Operators, Segmentation & Applications
Unit 11 of Image Processing: Explores how to detect edges, extract features, and segment images using gradient-based operators, thresholding, and morphological techniques—with real-world applications in medical imaging, autonomous vehicles, and object recognition.
TAKEAWAYS:
- Edges mark abrupt changes in intensity and are critical for segmentation and feature extraction.
- Gradient-based operators (Sobel, Prewitt, Laplacian) compute magnitude and direction to highlight edges.
- Thresholding and morphological operations refine edge detection for accurate segmentation.
- Feature extraction (Hough transform, moment invariants) enables pattern recognition in real-world images.
- Edge detection is used in medical imaging (X-rays), autonomous navigation (self-driving cars), and e-commerce (product recognition).
- Real-world examples include Pathao’s route optimization (edge detection for traffic flow analysis) and NEPSE’s stock chart analysis (trend line extraction).
1. Introduction to Edge Detection
Edges are discontinuities in image intensity caused by abrupt changes in brightness, texture, or color. They define object boundaries and are essential for:
- Image segmentation (separating objects from background).
- Feature extraction (identifying shapes, textures, and patterns).
- Object recognition (matching edges to known templates).
Why Detect Edges?
- Reduces data complexity (e.g., a 512×512 image has ~260K pixels; edges may reduce this to ~10K).
- Enables shape analysis (e.g., detecting a car’s wheels in autonomous driving).
- Helps in medical imaging (e.g., detecting tumors in X-rays).
2. Types of Grey-Level Discontinuities
Edges can be classified based on intensity changes:
- Impulse (step) discontinuity: Sharp transition (e.g., edge of a coin).
- Roof discontinuity: Peak or valley (e.g., shadow boundary).
- General discontinuity: Complex transitions (e.g., textured edges).
flowchart TD
A["Edge Type"] --> B["Impulse (Step)"]
A --> C["Roof (Peak/Valley)"]
A --> D["General"]
B -->|"Example"| E["Coin Edge"]
C -->|"Example"| F["Shadow Boundary"]
D -->|"Example"| G["Textured Edge"]3. Gradient-Based Edge Detection
Edges are detected by computing intensity gradients (rate of change in pixel values). The gradient has:
- Magnitude: Strength of the edge.
- Direction: Orientation of the edge.
Gradient Operators
| Operator | Kernel (3×3) | Sensitive To | Notes |
|---|---|---|---|
| Prewitt | [-1 0 +1; -1 0 +1; -1 0 +1] |
Diagonal edges | Less sensitive to noise. |
| Sobel | [-1 -2 -1; 0 0 0; +1 +2 +1] |
Horizontal/vertical | More robust to noise. |
| Laplacian | [0 1 0; 1 -4 1; 0 1 0] |
Second derivative | Highlights zero-crossings. |
4. Worked Example: Prewitt Operator
Given image (3×3 pixels):
| 0 | 30 | 60 |
|----|----|----|
| 5 | 32 | 62 |
| 10 | 38 | 64 |
Prewitt operator (horizontal):
[-1 0 +1] × [5 32 62] = (-1×5 + 0×32 + 1×62) = **57**
[-1 0 +1] × [10 38 64] = (-1×10 + 0×38 + 1×64) = **54**
Gradient magnitude = √(57² + 54²) ≈ 78.5 (strong edge).
Direction = arctan(57/54) ≈ 42° (slightly diagonal).
5. Edge Detection Steps
- Compute gradients (using Sobel/Prewitt/Laplacian).
- Thresholding: Apply a threshold to classify pixels as edge or non-edge.
- Non-maximum suppression: Keep only local maxima in gradient direction.
- Hysteresis thresholding: Two thresholds (high/low) to connect weak edges.
- Edge linking: Connect disjoint edges into continuous boundaries.
flowchart TD
A["Input Image"] --> B["Apply Gradient Operator"]
B --> C["Compute Magnitude & Direction"]
C --> D["Non-Max Suppression"]
D --> E["Hysteresis Thresholding"]
E --> F["Edge Linking"]
F --> G["Final Edge Map"]6. Edge Detection in Real-World Applications
In the Real World
Pathao (Ride-Hailing App)
- Idea: Edge detection analyzes traffic flow by detecting vehicle boundaries in real-time camera feeds.
- How: Sobel operator highlights lane markings and vehicle edges to optimize route suggestions.
NEPSE (Stock Market)
- Idea: Trend line extraction using edge detection to identify support/resistance levels in stock charts.
- How: Canny edge detector isolates key price movement patterns for algorithmic trading.
Medical Imaging (e.g., X-rays)
- Idea: Tumor detection by highlighting abrupt intensity changes in bone scans.
- How: Laplacian of Gaussian (LoG) detects edges in CT scans for early cancer diagnosis.
7. Feature Extraction Beyond Edges
After edge detection, features (distinctive patterns) are extracted for recognition:
- Hough Transform: Detects lines/circles (e.g., license plate corners in surveillance).
- Moment Invariants: Shape descriptors (e.g., distinguishing a square from a circle).
- Texture Analysis: Uses GLCM (Gray-Level Co-occurrence Matrix) for material classification.
flowchart TD
A["Edge Detection"] --> B["Feature Extraction"]
B --> C["Hough Transform"]
B --> D["Moment Invariants"]
B --> E["Texture Analysis"]
C -->|"Example"| F["License Plate Detection"]
D -->|"Example"| G["Object Recognition"]
E -->|"Example"| H["Material Classification"]8. Comparison of Edge Detection Methods
| Method | Pros | Cons | Best For |
|---|---|---|---|
| Sobel Operator | Robust to noise | Sensitive to diagonal edges | General-purpose edge detection |
| Prewitt Operator | Simple, fast | Less accurate than Sobel | Low-complexity images |
| Canny Edge | Optimal thresholding | Computationally expensive | High-precision applications |
| Laplacian | Highlights fine details | Prone to noise | Zero-crossing detection |
9. Worked Example: Canny Edge Detector
Steps:
- Gaussian blur (reduce noise).
- Gradient computation (Sobel).
- Non-maximum suppression (thin edges).
- Double thresholding (high/low thresholds).
- Edge tracking (connect weak edges).
Input (blurred image):
| 25 | 30 | 28 |
|----|----|----|
| 32 | 40 | 38 |
| 29 | 35 | 33 |
After Sobel:
| 5 | 0 | -3 |
|----|----|----|
| 10 | 0 | -7 |
Thresholding (T_high=15, T_low=8):
- Pixels ≥15 → strong edge.
- Pixels <15 but connected to strong edges → weak edge.
- Others → discarded.
Output:
| | | |
|---|---|---|
| E | E | |
| | | |
(E = Edge)
10. Edge Detection in Binary Images (Logical Operations)
Binary images (black/white) use AND/OR/XOR for masking and feature extraction:
- AND: Retains pixels where both images are 1.
- OR: Retains pixels where either image is 1.
- XOR: Highlights differences between images.
Example: Masking a Coin
Original Image:
| 0 | 0 | 1 |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 | 1 |
Mask (Circle):
| 0 | 0 | 0 |
|---|---|---|
| 0 | 1 | 0 |
| 0 | 0 | 0 |
AND Result:
| 0 | 0 | 0 |
|---|---|---|
| 0 | 1 | 0 |
| 0 | 0 | 0 |
Exam Tip
- Focus on gradient operators (Sobel, Prewitt, Laplacian) and their kernels.
- Practice thresholding (hysteresis, non-maximum suppression).
- Compare methods (e.g., Sobel vs. Canny) in your answers.
- Real-world link: Always tie edge detection to Pathao’s traffic analysis or NEPSE’s stock charts in explanations.
- Worked examples: Show step-by-step gradient computation and thresholding logic for full marks.
- Common mistake: Forgetting to normalize gradients before thresholding. Always divide by √(Gx² + Gy²).
Based on the TU BSc CSIT syllabus for Image Processing (CSC332), unit 11.
Discussion
Loading…