Chapter 19 of 22 Part IV: Information Processing

When Machines Learn to See

Each project below is tailored to a specific algorithm and scientific question from Chapter 19, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.

Project 1 of 3 · v1-c19-p01 Intermediate · ~30 min

3×3 Sobel Edge-Detection Convolution Lab

Lab activity: 1. Find the edges · Related code: block-01.js, block-04.js · Pioneer: View profile

Real-World Problem: Self-driving cars and document scanners must locate object boundaries inside raw pixel arrays.
Scientific Question: Why does a 3×3 convolution kernel with balanced positive and negative weights vanish on flat surfaces and peak at edges?

Objective: Apply horizontal and vertical 3×3 edge kernels to a synthetic grayscale grid and compute edge magnitude.

Hypothesis to Test: Applying kernel [[-1,0,1],[-2,0,2],[-1,0,1]] outputs 0 on solid patches and strong responses along vertical dark-to-light transitions.

Step-by-Step Implementation

  1. Represent an 8×8 grayscale image as a 2D array of integers 0–255.
  2. Slide a 3×3 vertical Sobel kernel over interior pixels (1..6, 1..6) computing weighted sums.
  3. Repeat with a horizontal Sobel kernel and combine via sqrt(Gx^2 + Gy^2).
  4. Test a completely uniform image (all 128s) and verify every output pixel is 0.
Concrete Input: 8×8 grayscale grid with a dark left half (20) and bright right half (220).
Expected Output: Interior flat pixels -> Gx = 0; boundary column -> Gx = +800 (clamped to 255 bright edge).

Test Cases: Uniform 128 grid -> all 0; Vertical step -> strong vertical edge, horizontal edge = 0.

Boundary Condition: Border pixels (row 0, col 0, etc.) require zero-padding, clamping, or skipping.

Common Mistake to Avoid: Overwriting the input array in-place while still reading neighboring pixels for the next cell.

Interpreting Results: Local linear filters extract edges and textures that form the first layers of both classical vision and CNNs.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 19 before testing the boundary case: Border pixels (row 0, col 0, etc.) require zero-padding, clamping, or skipping.

Extension Challenge: Swap in a 3×3 averaging blur kernel (all 1/9) and verify it smooths out single-pixel salt-and-pepper noise.

Reflection Question: How did Paul Viola and Michael Jones's fast rectangular features enable real-time face detection on early cameras?

Project 2 of 3 · v1-c19-p02 Intermediate · ~25 min

Tiny 5×5 Pixel-Digit Template Classifier

Lab activity: 2. Read a tiny digit · Related code: block-02.js · Pioneer: View profile

Real-World Problem: Postal sorting machines classify millions of handwritten digits by comparing pixel patterns.
Scientific Question: How well does simple pixel-by-pixel similarity recognize centered vs. shifted handwritten digits?

Objective: Score a 5×5 drawn digit against reference templates (0–9) using dot-product / L1 distance and test translation sensitivity.

Hypothesis to Test: A centered "1" matches cleanly, while shifting the exact same stroke 1 pixel left sharply drops naive template score.

Step-by-Step Implementation

  1. Define 5×5 binary templates for digits 0, 1, 2, 3, 4.
  2. Compute pixel agreement score between a test drawing and each template.
  3. Flip 2 noisy pixels and verify the classifier still picks the right digit.
  4. Shift the drawing by 1 column and observe why raw pixel templates struggle with translation.
Concrete Input: 5×5 binary grid for digit "0" vs. digit "0" shifted 1 column right.
Expected Output: Centered -> top match "0" (score 25/25); Shifted -> score drops sharply (motivates centering/CNNs).

Test Cases: Exact template -> 25/25; 2 flipped pixels -> 23/25 (correct); Shifted -> degraded.

Boundary Condition: Blank 5×5 grid should output "No ink detected" rather than guessing a random digit.

Common Mistake to Avoid: Assuming high accuracy on clean centered templates generalizes to rotated or shifted handwriting.

Interpreting Results: Translation sensitivity motivated bounding-box normalization and convolutional neural networks (Yann LeCun).

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 19 before testing the boundary case: Blank 5×5 grid should output "No ink detected" rather than guessing a random digit.

Extension Challenge: Add automatic center-of-mass alignment before template matching and re-test the shifted digit.

Reflection Question: Why did Fei-Fei Li's ImageNet dataset transform computer vision as much as new algorithms did?

Project 3 of 3 · v1-c19-p03 Applied · ~25 min

Biometric Threshold (FAR vs. FRR) Trade-Off Analyzer

Lab activity: 3. Review matching errors · Related code: block-03.js, block-04.js · Pioneer: View profile

Real-World Problem: Phone unlock and border gates turn continuous similarity scores into binary Accept/Reject decisions.
Scientific Question: Why does moving a single decision threshold always trade False Acceptance Rate (FAR) against False Rejection Rate (FRR)?

Objective: Sweep a threshold across fictional genuine vs. impostor score distributions and locate the Equal Error Rate (EER).

Hypothesis to Test: Raising the threshold from 0.50 to 0.90 reduces FAR toward 0% while increasing FRR.

Step-by-Step Implementation

  1. Load the fictional genuine and impostor similarity arrays.
  2. For each candidate threshold T, compute FAR = impostors >= T and FRR = genuines < T.
  3. Find the threshold minimizing |FAR − FRR| (Equal Error Rate).
  4. Compare appropriate threshold choices for a bank vault vs. a photo-album tagger.
Concrete Input: 10 genuine scores [0.72..0.96] and 10 impostor scores [0.15..0.78]; sweep threshold 0.10 to 0.95.
Expected Output: Threshold 0.60 -> FAR=20%, FRR=0%; Threshold 0.80 -> FAR=0%, FRR=20%; EER near 0.75.

Test Cases: T = 0.0 -> FAR=100%, FRR=0%; T = 1.0 -> FAR=0%, FRR=100%.

Boundary Condition: If genuine and impostor distributions overlap, NO threshold can achieve 0% FAR and 0% FRR simultaneously.

Common Mistake to Avoid: Evaluating a security classifier using overall accuracy alone when impostors are rare or common.

Interpreting Results: Threshold engineering is a policy and safety decision, not purely a math constant.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 19 before testing the boundary case: If genuine and impostor distributions overlap, NO threshold can achieve 0% FAR and 0% FRR simultaneously.

Extension Challenge: Check how performance differs if two demographic groups have slightly shifted score distributions (fairness audit).

Reflection Question: What real-world harms happen when biometric systems are deployed without measuring subgroup error rates?