Image ProcessingUnit 1013 min read
Pattern Recognition & Shape Analysis: Features, Classifiers & Shape Descriptors
Unit 10 of Image Processing covers pattern recognition frameworks (Bayesian, neural, syntactic), shape analysis (boundary/region descriptors), and real-world applications in biometrics, medical imaging, and OCR. Learn how to extract features, classify patterns, and quantify shapes using chain codes, Fourier descriptors
TAKEAWAYS:
- Pattern recognition is the automated classification of objects (e.g., digits, faces) using features like edges, textures, or statistical moments, with decision-theoretic methods minimizing misclassification errors via Bayes’ theorem.
- Shape analysis quantifies objects via boundary descriptors (chain codes, Fourier descriptors) or region descriptors (moments, Zernike polynomials), enabling tasks like handwritten signature verification or tumor segmentation.
- Decision-theoretic classifiers (Bayesian, minimum-distance) rely on probability distributions of features, while structural classifiers (syntactic, neural) model patterns as grammars or hierarchical networks.
- Chain codes represent object boundaries as 8-directional sequences, while Fourier descriptors capture shape spectra for rotation/scale invariance—critical for OCR and fingerprint matching.
- Moment invariants (Hu moments) describe shape properties (area, orientation) independently of affine transformations, used in license plate recognition (NTC) and satellite image analysis.
- Mexican Hat filters (DoG) detect edges via second-derivative zero-crossings, forming the backbone of feature extraction in SIFT and edge-based segmentation.
1. Pattern Recognition: From Pixels to Decisions
Pattern recognition (PR) is the process of assigning labels (classes) to input data (e.g., images, signals) based on learned features. It combines:
- Feature extraction: Converting raw pixels into meaningful descriptors (e.g., edges, textures).
- Classification: Mapping features to classes using statistical, structural, or neural models.
1.1 Definitions: Pattern vs. Pattern Class
- Pattern: A set of measurements (features) describing an object. Example: A 16×16 pixel handwritten digit’s edge density and curvature.
- Pattern class: A category of similar patterns (e.g., "digit ‘5’" or "malignant tumor").
- Feature vector: A numerical representation of a pattern (e.g.,
[edge_count, texture_energy, compactness]).
Example of 28×28 pixel patterns for digits 0–9. (Image: Suvanjanprasai, CC BY-SA 4.0, via Wikimedia Commons)
1.2 Decision-Theoretic Methods: Minimizing Misclassification
These methods use probability theory to classify patterns by minimizing errors. Key approaches:
| Method | How It Works | Example Application | Advantages | Disadvantages |
|---|---|---|---|---|
| Bayesian Classifier | Assigns class based on posterior probability . Assumes features are independent. | eSewa’s face recognition (classify user vs. impostor). | Optimal if feature distributions are known. | Sensitive to feature independence assumption. |
| Minimum Distance | Classifies based on closest mean feature vector (Euclidean distance). | NTC’s license plate OCR (classify characters). | Simple, fast. | Fails with overlapping classes. |
| Parzen Window | Estimates probability density using kernel functions (e.g., Gaussian). | Medical imaging (tumor vs. healthy tissue). | Non-parametric, works with complex distributions. | Computationally expensive. |
| Neural Networks | Learns non-linear decision boundaries via backpropagation. | WhatsApp’s photo tagging (person/object detection). | Handles high-dimensional data. | Needs large training data. |
Worked Example: Bayesian Classification for eSewa Face Recognition Suppose eSewa’s system uses two features for face verification:
- : Eye distance (normalized).
- : Nose width (normalized).
Given:
- Class (User): , , .
- Class (Impostor): , , .
Test pattern: . Step 1: Compute likelihoods using Gaussian PDF: Step 2: Apply Bayes’ theorem: Result: → Classify as User.
2. Shape Analysis: Describing Objects Mathematically
Shape analysis quantifies geometric properties of objects for recognition. Approaches:
- Boundary-based: Describes the object’s outline.
- Region-based: Describes internal properties (e.g., moments).
- Hybrid: Combines both (e.g., SIFT descriptors).
2.1 Boundary Representation: Chain Codes
Chain codes represent an object’s boundary as a sequence of 8-directional steps (0–7). Example for a square:
Chain code for the square: {0, 1, 7, 7} (right, up, left, left).
Worked Example: Shape Number of a Chain Code
Given chain code {0, 7, 5, 4, 3, 1}:
- Convert to complex numbers: , , , etc.
- Sum the vectors: .
- Shape number = angle of the sum: (180°).
Application: Used in signature verification (e.g., bank checks). A forged signature’s chain code will have a different shape number than the genuine one.
2.2 Fourier Descriptors: Shape Spectra
Fourier descriptors decompose a shape’s boundary into frequency components, enabling:
- Rotation/scale invariance: Phase and magnitude of Fourier coefficients.
- Noise robustness: Low-frequency coefficients capture coarse shape.
Steps:
- Trace boundary as .
- Compute DFT: .
- Use first coefficients (e.g., ) for description.
Example: A circle’s Fourier descriptor will have a dominant DC component (constant magnitude).
Worked Example: Daraz Product Logo Recognition Suppose Daraz’s logo is a stylized "D" with boundary points: Compute and retain (low frequencies). A rotated/scaled "D" will have the same magnitude spectrum for these coefficients.
2.3 Region-Based Descriptors: Moments and Invariants
Moments capture an object’s intensity distribution. The -th moment is: Central moments (shifted to origin):
Hu Moments (7 invariants under rotation/scale): where .
Worked Example: NTC License Plate Recognition A license plate has a rectangular shape. Compute its Hu moments:
- Binary threshold the plate region.
- Compute for .
- Calculate :
- captures compactness (rectangles have low ).
- captures orientation (rectangles have if axis-aligned).
Comparison Table: Shape Descriptors
| Descriptor | Type | Invariance | Example Use Case | Limitations |
|---|---|---|---|---|
| Chain Code | Boundary | Translation | Signature verification | Sensitive to noise/rotation. |
| Fourier Descriptors | Boundary | Rotation, Scale | Logo recognition (Daraz) | Computationally intensive. |
| Hu Moments | Region | Rotation, Scale, Translation | License plate OCR (NTC) | Loses fine details. |
| Zernike Polynomials | Region | Rotation | Medical image analysis | Complex to compute. |
3. Structural Pattern Recognition
Models patterns as hierarchical structures (e.g., grammars, graphs). Used in:
- Syntactic methods: Parse patterns using formal grammars (e.g., scene analysis).
- Graph matching: Compare objects as graphs (e.g., molecular structures).
Example: WhatsApp’s sticker recognition uses graph-based matching to identify emoji shapes.
4. Edge Detection and Feature Extraction: Mexican Hat Filters
The Mexican Hat filter (DoG: Difference of Gaussians) detects edges via second derivatives: where is a Gaussian kernel.
Steps:
- Convolve image with DoG at multiple scales.
- Find zero-crossings (edges) where the response changes sign.
Worked Example: NEPSE Stock Chart Edge Detection A stock price chart (e.g., NEPSE index) can be edge-detected to find:
- Support/resistance levels (horizontal edges).
- Trend changes (vertical edges).
In the Real World
eSewa’s Face Recognition
- Idea: Bayesian classification of facial features (eye distance, nose width).
- How: Uses a decision-theoretic approach to minimize impostor acceptance rate. Features are extracted via Haar cascades, then classified with a trained Gaussian model.
- Nepali context: Enables secure mobile payments by verifying user identity before transactions.
NTC’s License Plate Recognition
- Idea: Hu moments for shape invariance + OCR for character recognition.
- How: Plates are segmented, their rectangular shape is verified using and , then characters are classified via template matching.
- Nepali context: Automates traffic violations and toll collection at highways.
Pathao’s Driver App Route Optimization
- Idea: Fourier descriptors for shape matching of city blocks.
- How: Pathao’s algorithm compares the shape of a driver’s current route to precomputed "block signatures" (Fourier descriptors of road networks) to suggest optimal paths.
- Nepali context: Reduces fuel costs and delivery times in Kathmandu’s chaotic traffic.
Exam Tip
Definitions:
- Always define pattern, pattern class, and feature vector clearly. For example:
"A pattern is a set of measurements representing an object, while a pattern class groups similar patterns (e.g., all handwritten ‘A’s)."
- For shape number, state:
"The shape number is the angle of the resultant vector obtained by summing chain code directions, used to quantify boundary orientation."
- Always define pattern, pattern class, and feature vector clearly. For example:
Decision-Theoretic Methods:
- Bayesian classifiers are favored in exams. Show the formula:
- Minimum-distance classifiers are simpler; draw a 2D feature space with class means and decision boundaries.
Shape Analysis:
- Chain codes: Practice converting simple shapes (circle, square) to chain codes. Memorize the 8-directional codes (0=right, 1=upper-right, etc.).
- Fourier descriptors: Explain invariance by saying "low-frequency coefficients are rotation/scale-invariant."
- Hu moments: List the 7 invariants and their geometric meanings (e.g., = compactness).
Worked Examples:
- Bayesian classification: Always show the likelihood calculation step.
- Chain code shape number: Given a chain code, compute the resultant vector and its angle.
- Hu moments: For a rectangle, state that (symmetric about axes).
Applications:
- Link Mexican Hat filters to edge detection in medical imaging (e.g., detecting tumor boundaries).
- Relate Fourier descriptors to logo recognition (e.g., Daraz’s "D" vs. fake copies).
- Moment invariants are key for license plate recognition—mention NTC’s use case.
Common Pitfalls:
- Chain codes: Forgetting to normalize for starting point (use Freeman’s convention: start at the top-leftmost pixel).
- Bayesian assumptions: Not stating that features must be independent.
- Fourier descriptors: Using too few coefficients (lose shape details).
Figure: Pipeline for pattern recognition in real-world systems.
Based on the TU BSc CSIT syllabus for Image Processing (CSC332), unit 10.
Discussion
Loading…