CMP362 Image Processing and Pattern Recognition

Image Processing and Pattern RecognitionUnit 1010 min read

Pattern Recognition: Classifiers, Features & Real-World Systems

Unit 10 of Image Processing and Pattern Recognition covers supervised/unsupervised learning, feature extraction, classifier design (Bayes, SVM, NN), and real-world applications in biometrics, medical diagnosis, and autonomous systems—with visual workflows, math traces, and Nepalese examples like Ncell’s fraud detection

Core Concepts: What is Pattern Recognition?

Pattern Recognition (PR) is the automated process of identifying regularities in data to classify objects, predict outcomes, or make decisions. It bridges feature extraction (representing data meaningfully) and classification (assigning labels). Key steps:

  1. Data Acquisition: Raw input (images, signals, text).
  2. Preprocessing: Noise removal, normalization.
  3. Feature Extraction: Convert data into numerical features (e.g., edges, textures).
  4. Classifier Training: Learn decision boundaries (e.g., "cat vs. dog").
  5. Testing/Deployment: Apply to new data.

1. Feature Extraction: From Pixels to Meaning

Features are quantifiable properties that distinguish classes. Common methods:

  • Spatial Domain: Pixel intensity, edges (Sobel, Canny), histograms, texture (GLCM).
  • Transform Domain: Fourier coefficients, wavelet transforms.
  • Deep Learning: Autoencoders extract hierarchical features.

Worked Example: Edge Detection in Traffic Signs

Problem: Classify a blurred traffic sign (e.g., "Stop" vs. "Speed Limit 40"). Steps:

  1. Preprocess: Apply Gaussian blur to reduce noise.
    blurred = cv2.GaussianBlur(gray_image, (5,5), 0)
    
  2. Edge Detection: Use Canny edge detector (thresholds: low=50, high=150).
    edges = cv2.Canny(blurred, 50, 150)
    
  3. Feature Vector: Count edge pixels in 8 regions (histogram of oriented gradients, HOG). Output Feature Vector: [120, 80, 30, 5, 200, 150, 10, 0] (regions 1–8). Visualization:
    
    

Why This Matters:

  • Ncell’s Fraud Detection: Uses edge/texture features to flag altered receipts in mobile payments.
  • Pathao’s Driver Verification: Extracts facial landmarks (features) to match driver IDs.

2. Classifiers: Decision-Making Engines

Classifiers map features to labels. Compare three key types:

Classifier How It Works Pros Cons Example Use Case
Bayesian Probabilistic (e.g., Naive Bayes): Fast, works with small data Assumes feature independence Spam email filtering (Khalti)
Support Vector Machine (SVM) Finds hyperplane maximizing margin between classes. Effective in high dimensions Slow for large datasets Handwritten digit recognition (Nepalese bank cheques)
Neural Networks (NN) Multi-layer perceptron with activation functions (e.g., ReLU). Learns complex patterns Needs huge data, training time Facial recognition (eSewa login)

Worked Example: SVM for Loan Approval

Scenario: A bank (e.g., NMB) approves loans based on:

  • Features: income, credit_score, loan_amount, employment_years.
  • Classes: Approved (1) or Rejected (0).

Step-by-Step:

  1. Train Data:

    Income (₹) Credit Score Loan (₹) Employment (yrs) Class
    50,000 700 200,000 5 1
    30,000 500 100,000 2 0
  2. SVM Training:

    • Kernel: Linear (for simplicity).
    • Decision boundary: 0.001*income + 0.005*credit_score - 0.002*loan - 0.1*employment = threshold.
    • Visualization:
      flowchart TD
        A["Income (₹)"] --> B["Credit Score"]
        B --> C["Decision Boundary: y = 0.001x1 + 0.005x2 - 0.002x3 - 0.1x4"]
        C --> D["Class 1\n(Approved)"]
        C --> E["Class 0\n(Rejected)"]
  3. Test Case:

    • New applicant: income=40,000, credit_score=650, loan=150,000, employment=3.
    • Calculation: 0.001*40000 + 0.005*650 - 0.002*150000 - 0.1*3 = -120.5 → Rejected (below threshold).

Real-World Tie-In:

  • Nepal Rastra Bank (NRB): Uses SVM to detect counterfeit currency by analyzing edge features and texture.

3. Supervised vs. Unsupervised Learning

Aspect Supervised Learning Unsupervised Learning
Labels Data is labeled (e.g., "cat", "dog"). No labels; finds hidden patterns.
Goal Predict labels for new data. Cluster similar data (e.g., customer segments).
Examples SVM, Decision Trees, NNs. K-means, PCA, Hierarchical Clustering.
Nepalese Use Case NTC’s network traffic classification (malicious vs. normal). Daraz’s recommendation system (grouping similar products).

Worked Example: K-Means for Traffic Congestion Zones

Problem: Divide Kathmandu into 3 congestion zones based on GPS data. Steps:

  1. Data: 1000 GPS points with (latitude, longitude, speed).
  2. K-means Algorithm:
    • Initialize 3 centroids randomly.
    • Assign each point to the nearest centroid.
    • Recalculate centroids (mean of assigned points).
    • Repeat until convergence.
  3. Result:
    • Cluster 1: High speed (ring road).
    • Cluster 2: Low speed (Thapathali).
    • Cluster 3: Medium speed (Koteshwor). Visualization:
    
    

4. Deep Learning for Pattern Recognition

Neural Networks (NNs) automate feature extraction and classification. Key components:

  • Layers:
    • Input Layer: Raw pixels/values.
    • Hidden Layers: Feature learning (e.g., ConvNet for images).
    • Output Layer: Probabilities per class (softmax).
  • Activation Functions:
    • ReLU: (avoids vanishing gradients).
    • Sigmoid: (binary classification).
  • Loss Functions:
    • Cross-Entropy: Measures prediction error for classification.
    • MSE: Mean Squared Error (regression).

Worked Example: CNN for COVID-19 X-Ray Classification

Architecture:

graph TD
  A["Input: 224x224 X-Ray"] --> B["Conv2D (32 filters, 3x3)"]
  B --> C["ReLU"]
  C --> D["MaxPooling (2x2)"]
  D --> E["Conv2D (64 filters)"]
  E --> F["ReLU"]
  F --> G["Flatten"]
  G --> H["Dense (128 neurons)"]
  H --> I["Softmax: COVID/Normal"]

Training:

  • Dataset: 1000 X-rays (500 COVID, 500 normal).
  • Loss: Categorical Cross-Entropy.
  • Output: 92% accuracy on test data.

Real-World Use:

  • Nepal’s Health Facilities: Deployed in Bir Hospital for rapid triage using mobile apps.

In the Real World

  1. eSewa’s Biometric Login:

    • Idea: Feature Extraction + SVM.
    • How: Extracts facial landmarks (eyes, nose, mouth) and matches against a trained SVM model to authenticate users. Reduces fraud in digital payments.
  2. Ncell’s Network Optimization:

    • Idea: Unsupervised Clustering (K-means).
    • How: Groups cell towers with similar traffic patterns to dynamically allocate bandwidth, reducing latency during peak hours (e.g., IPL matches).
  3. Daraz’s Product Recommendations:

    • Idea: Collaborative Filtering + Neural Networks.
    • How: Uses user purchase history (features) and a deep autoencoder to recommend products (e.g., "Customers who bought this also bought...").
  4. Nepal Police’s Number Plate Recognition:

    • Idea: Optical Character Recognition (OCR) + CNN.
    • How: Captures traffic camera images, applies edge detection (Canny), then a CNN to read plates and flag stolen vehicles.

Exam Tip

  1. Diagrams Are Mandatory:

    • Draw decision trees, neural network layers, or SVM margins for 5+ marks. Label every node/arrow.
    • Example: For a question on "Compare SVM and NN," sketch both architectures side-by-side.
  2. Math Traces Get Full Marks:

    • For Bayesian classifiers, show the full probability equation with given values.
    • For K-means, write the update rule for centroids: where is cluster .
  3. Real-World Applications:

    • Link every concept to a Nepalese example (e.g., "Ncell uses SVM for..."). Examiners love this.
    • Avoid: Generic answers like "used in healthcare." Specify the technology (e.g., "CNN in Bir Hospital’s X-ray app").
  4. Common Pitfalls:

    • Confusing Supervised/Unsupervised: Always state whether labels are present.
    • SVM Kernels: If asked about non-linear data, mention RBF kernel without deriving it.
    • Overfitting: In NNs, say "Dropout layers prevent overfitting" without extra details.
  5. Practical Questions:

    • Expect code snippets (e.g., "Write Python for K-means initialization").
    • Trace one iteration of an algorithm (e.g., show how centroids move in K-means).

Summary Table: Classifier Selection Guide

Scenario Recommended Classifier Why?
Small dataset, fast prediction Naive Bayes Low computational cost.
High-dimensional data (e.g., images) SVM (RBF kernel) Handles non-linearity well.
Large dataset, complex patterns Neural Network Learns hierarchical features.
No labels, exploratory analysis K-means Unsupervised clustering.
Sequential data (e.g., time series) Hidden Markov Model (HMM) Models state transitions.

Final Visual: End-to-End PR Pipeline

flowchart LR
  A["Raw Data\n(e.g., Traffic Camera Image)"] --> B["Preprocessing\nNoise Removal, Normalization"]
  B --> C["Feature Extraction\nCanny Edges, HOG"]
  C --> D["Classifier\nSVM/NN"]
  D --> E["Decision\n'Stop Sign Detected'"]
  E --> F["Action\nAlert Traffic Control"]
  F -->|"Feedback"| A

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

Discussion

Loading…