v9.1.1
Menu

Chapter 7: Feature Detection and Matching

Week 7-8

Points, patches, edges, contours, lines, vanishing points, and segmentation techniques.

Topics
4
Demo
1
Videos
3
Min read
29

Chapter Overview

How do we find corresponding points between two images? This classic problem underlies image stitching, 3D reconstruction, object tracking, and more. The solution: find distinctive features and match them.

What is this chapter about? We study how to detect interesting points (corners, blobs), describe them in a way that's robust to changes in viewpoint and lighting, and match them between images.

Why does this matter? Feature matching is the foundation for:

  • Panorama stitching: Finding overlapping regions between photos
  • Visual SLAM: Tracking camera motion through a scene
  • Object recognition: Matching templates to images
  • Image retrieval: Finding similar images in a database

How the topics connect: We start with feature detectors that find interesting points—corners, blobs, edges. Then feature descriptors encode the local appearance around each point. Finally, we learn matching strategies that robustly pair up corresponding features despite noise and outliers.

Chapter Roadmap

Click any topic to jump in

Explainer videoInteractive demo
1
Feature Detectors

Harris, SIFT, FAST, and ORB — finding distinctive points like corners and blobs that are repeatable across views.

Harris Corner DetectorSIFT KeypointsFAST Corner DetectorORB Features
2
Edge Detection

Gradients, Sobel, Canny, and LoG — finding boundaries and contours through intensity change analysis.

Image GradientSobel OperatorCanny Edge DetectorLaplacian of Gaussian (LoG)
Encoding and matching detected features
3
Feature Descriptors

SIFT and BRIEF descriptors, ratio test, and cross-check — encoding local appearance for robust matching.

SIFT DescriptorBRIEF DescriptorLowe's Ratio TestCross-Check Matching
Structured geometric detection
4
Hough Transform

Accumulator-based voting for lines and circles — detecting structured geometric shapes from edge pixels.

Hough Transform for LinesAccumulator ArrayHough for CirclesProbabilistic Hough Transform

Topics

4 topics in this chapter

Chapter 6 taught networks to recognize whole objects, but a different family of vision tasks — stitching a panorama, tracking a camera through a room, reconstructing 3D from photos — hinges on a lower-level question: which individual points in two images correspond to the same physical spot? You cannot match every pixel, because most pixels look like their neighbours and matching them is hopelessly ambiguous. The trick is to first find a sparse set of points that are both distinctive, so they stand out from their surroundings, and repeatable, so the same world point is found again after the viewpoint or lighting changes. Corners fit both criteria beautifully: unlike a flat wall or a straight edge, a corner is pinned down in two directions at once. This topic surveys how detectors find such points. The Harris detector reads local gradient structure, SIFT adds scale invariance through a scale-space search, and FAST and ORB trade some robustness for the raw speed that real-time SLAM demands.

Definition

A feature detector is an algorithm that locates sparse, distinctive, and repeatable interest points — typically corners or blobs — in an image, so that the same physical points can be re-found reliably across different views for subsequent description and matching.

In this topic

  1. 1Harris Corner Detector
  2. 2SIFT Keypoints
  3. 3FAST Corner Detector
  4. 4ORB Features
1 of 4
Harris Corner Detector

R=det⁡(M)−k⋅trace(M)2 where M=[∑Ix2∑IxIy∑IxIy∑Iy2]R = \det(M) - k \cdot \text{trace}(M)^2 \text{ where } M = \begin{bmatrix} \sum I_x^2 & \sum I_x I_y \\ \sum I_x I_y & \sum I_y^2 \end{bmatrix}

A good interest point should change in appearance no matter which direction you shift a small window over it — that is what makes a corner, and the Harris detector measures it. It builds the structure tensor MM from image gradients IxI_x and IyI_y summed over a window, where MM is the 2×22 \times 2 matrix of gradient products. The two eigenvalues of MM summarise the local shape: both large means a corner, one large means an edge, both small means a flat region. Rather than solve for eigenvalues, Harris scores each pixel with R=det⁡(M)−k⋅trace(M)2R = \det(M) - k \cdot \text{trace}(M)^2, using sensitivity kk near 0.05. Its weakness is scale: a corner at one zoom can read as an edge at another, which is exactly the gap SIFT closes.

Mathematical Intuition

The structure tensor M=∑w[Ix2IxIyIxIyIy2]M = \sum_w \begin{bmatrix} I_x^2 & I_x I_y \\ I_x I_y & I_y^2 \end{bmatrix} is a 2×22 \times 2 symmetric positive semi-definite matrix. Its eigenvalues λ1,λ2\lambda_1, \lambda_2 characterize local gradient distribution: both large (corner), one large (edge), both small (flat). The Harris response R=λ1λ2−k(λ1+λ2)2=det⁡(M)−k⋅trace(M)2R = \lambda_1 \lambda_2 - k(\lambda_1 + \lambda_2)^2 = \det(M) - k \cdot \text{trace}(M)^2 avoids explicit eigenvalue computation (which requires solving a quadratic) by using the determinant-trace relationship. The parameter k∈[0.04,0.06]k \in [0.04, 0.06] controls sensitivity: larger kk requires both eigenvalues to be more equal. Harris corners are rotation-invariant because eigenvalues of MM are invariant under rotation, but NOT scale-invariant — a corner detected at one scale may be an edge at another.

2 of 4
SIFT Keypoints

D(x,y,σ)=L(x,y,kσ)−L(x,y,σ)D(x, y, \sigma) = L(x, y, k\sigma) - L(x, y, \sigma)

Harris finds corners at a single scale, but a building corner photographed up close and far away needs to match despite the size change. SIFT earns scale invariance by searching a scale-space: the image is repeatedly blurred with Gaussians at increasing σ\sigma, and adjacent blurred images are subtracted to form the Difference of Gaussians D(x,y,σ)=L(x,y,kσ)−L(x,y,σ)D(x,y,\sigma) = L(x,y,k\sigma) - L(x,y,\sigma), which cheaply approximates the scale-normalised Laplacian — the optimal blob detector. Keypoints are the local extrema of DD across both space and scale, so each feature is detected at its own characteristic size. Low-contrast and edge-like extrema are discarded to keep only stable points. This scale search is more expensive than Harris but is what lets SIFT features match across zoom and, with a descriptor, across viewpoint.

Mathematical Intuition

SIFT builds a scale-space L(x,y,σ)=G(x,y,σ)∗I(x,y)L(x, y, \sigma) = G(x, y, \sigma) * I(x, y) by convolving with Gaussians at σ,kσ,k2σ,...\sigma, k\sigma, k^2\sigma, .... The Difference of Gaussians D=L(kσ)−L(σ)≈(k−1)σ2∇2G∗ID = L(k\sigma) - L(\sigma) \approx (k-1)\sigma^2 \nabla^2 G * I approximates the scale-normalized Laplacian, which is the optimal blob detector. Keypoints are local extrema in 3D (x,y,σ)(x, y, \sigma) space — compared against 26 neighbors (8 spatial + 9 above + 9 below). Sub-pixel localization fits a 3D quadratic D(x)≈D+∂DTx+12xTHxD(\mathbf{x}) \approx D + \partial D^T \mathbf{x} + \frac{1}{2}\mathbf{x}^T H \mathbf{x} and solves x^=−H−1∇D\hat{\mathbf{x}} = -H^{-1}\nabla D. Keypoints with ∣D(x^)∣<0.03|D(\hat{\mathbf{x}})| < 0.03 (low contrast) or edge ratio trace(H)2/det⁡(H)>(r+1)2/r\text{trace}(H)^2/\det(H) > (r+1)^2/r (typically r=10r=10) are rejected.

3 of 4
FAST Corner Detector

Corner if ∃ n contiguous pixels pi where I(pi)>I(c)+t\text{Corner if } \exists \text{ n contiguous pixels } p_i \text{ where } I(p_i) > I(c) + t

SIFT is robust but far too slow for a phone tracking its own motion at 30 frames per second, so FAST trades invariance for raw speed. It examines a ring of 16 pixels on a Bresenham circle around a candidate centre cc and declares a corner when nn contiguous ring pixels are all brighter than I(c)+tI(c)+t or all darker than I(c)−tI(c)-t, with n=12n=12 the common choice. A learned decision tree first tests only the four compass points, rejecting most non-corners in a couple of comparisons, which is why FAST runs tens of times faster than Harris. The cost of that speed is real: FAST is not scale-invariant, assigns no orientation, and fires many adjacent detections, so non-maximum suppression on corner strength is needed to thin them.

Mathematical Intuition

FAST examines a Bresenham circle of 16 pixels at radius 3 around candidate pixel cc. The test checks if nn contiguous pixels are all brighter than I(c)+tI(c) + t or all darker than I(c)−tI(c) - t. For FAST-12 (n=12n=12), a corner requires 12 of 16 contiguous pixels to pass. The algorithm uses a decision tree learned from training images to achieve O(1)O(1) average-case per pixel: it first checks pixels 1, 9, then 5, 13 (the cardinal directions). If none of the four cardinal pixels deviate from I(c)I(c) by more than tt, the point is rejected immediately. This early rejection makes FAST 20-40x faster than Harris. However, FAST lacks sub-pixel precision, has no orientation assignment, and detects many adjacent corners — non-maximum suppression using the sum of absolute differences (corner strength) is needed.

4 of 4
ORB Features

ORB=oFAST (oriented FAST)+rBRIEF (rotated BRIEF)\text{ORB} = \text{oFAST (oriented FAST)} + \text{rBRIEF (rotated BRIEF)}

FAST is quick but bare — no orientation and no descriptor — and SIFT, while excellent, was long patent-encumbered. ORB (Oriented FAST and Rotated BRIEF) fuses the best of both into a free, real-time package. It takes FAST keypoints and assigns each an orientation from the intensity centroid, the direction from the patch centre to its centre of mass, giving rotation awareness that plain FAST lacks. It then computes a rotated BRIEF binary descriptor aligned to that orientation, so the same point yields the same bits even when the camera rolls. Because the descriptor is a bit string, matching uses Hamming distance — a single XOR and popcount — making ORB dramatically cheaper than SIFT's floating-point vectors. This is why ORB underpins so many real-time SLAM and mobile pipelines, connecting the corner idea back to the descriptor topic that follows.

Mathematical Intuition

ORB combines oFAST and rBRIEF. The orientation is computed from the intensity centroid: θ=atan2(m01,m10)\theta = \text{atan2}(m_{01}, m_{10}) where mpq=∑x,yxpyqI(x,y)m_{pq} = \sum_{x,y} x^p y^q I(x,y) are image moments within a patch. This gives rotation invariance — the descriptor is computed relative to θ\theta. rBRIEF computes 256 binary comparisons on a rotated sampling pattern: bi=1[I(Rθpi1)<I(Rθpi2)]b_i = \mathbf{1}[I(R_\theta p_i^1) < I(R_\theta p_i^2)] where RθR_\theta is the rotation matrix. The sampling pairs (pi1,pi2)(p_i^1, p_i^2) are preselected to maximize variance and minimize correlation. Matching uses Hamming distance — counting differing bits with XOR and POPCOUNT, which is a single CPU instruction. This makes matching O(d)O(d) with tiny constant, far faster than Euclidean distance on real-valued descriptors.

Theory Exercise

Problem:

The structure tensor M at a pixel has eigenvalues λ₁=100 and λ₂=5. Using k=0.04, compute the Harris response R. Is this a corner, edge, or flat region?

Hints:
  • det(M) = λ₁ × λ₂
  • trace(M) = λ₁ + λ₂
  • R = det(M) - k × trace(M)²
  • Corners have high R, edges have R ≈ 0, flat regions have R small