Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Fingerprints for image patches
To stitch two photos or track a robot’s motion, a computer must recognise the same spot in two images, even if the camera turned or the light changed. Raw pixel values change too much, so we summarise each patch by which way its edges point: a histogram of edge directions, like a small fingerprint. Measuring directions relative to the patch’s strongest direction makes the fingerprint survive rotation, and normalising it removes brightness changes. The demo builds such a histogram for a small patch with an edge.
Visual odometry on Mars rovers, satellite image co-registration and drone mapping all match keypoint descriptors between images thousands of times per second.
- 1. A descriptor summarises a patch by…
- 2. Rotation invariance comes from…
- 3. Normalising the histogram removes…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Gradients: central differences or Sobel give magnitude and orientation at each pixel. HOG uses unsigned orientations (0–180°, 9 bins) for objects whose contrast polarity varies; SIFT uses signed ones (0–360°, 8 bins).
- HOG (Dalal and Triggs, 2005): 8 × 8-pixel cells, 9-bin histograms with interpolated votes, 2 × 2-cell blocks with L2-Hys normalisation, blocks overlapping by one cell; a 64 × 128 pedestrian window gives 3780 features for a linear SVM. Deformable part models (Felzenszwalb et al., 2010) built on HOG.
- Keypoint detection: Harris corners (Harris and Stephens, 1988) use the structure tensor; SIFT finds extrema of the difference of Gaussians over position and scale (3 levels per octave, σ₀ = 1.6), rejects edges and low contrast, and refines positions.
- SIFT descriptor (Lowe, 1999, 2004): dominant orientation from a 36-bin histogram (extra keypoints for peaks above 80%); the 16 × 16 neighbourhood, rotated and scaled to the keypoint, is pooled into 4 × 4 cells × 8 bins = 128 values, normalised, clipped at 0.2 and renormalised. RootSIFT (Arandjelović and Zisserman, 2012) takes square roots for a Hellinger distance.
- Matching: nearest neighbour with Lowe’s ratio test (accept if d₁ / d₂ is below about 0.8), mutual nearest neighbours, then RANSAC on a geometric model; approximate search with FLANN or FAISS.
- Faster and binary: SURF (Bay et al., 2006), FAST corners, BRIEF, ORB (Rublee et al., 2011; 256 bits, Hamming distance), used in ORB-SLAM3 (2021).
- Learned (2018–2026): SuperPoint, D2-Net, DISK and ALIKED detectors and descriptors; SuperGlue, LoFTR and LightGlue matchers; dense DINOv2 features for semantic correspondence. SIFT remains the default in COLMAP and a strong baseline in benchmarks such as the Image Matching Challenge.
- 1. Standard SIFT descriptors have…
- 2. ORB descriptors are compared with…
- 3. Lowe's ratio test rejects a match when…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Computing and matching descriptors
Exercise 1.
- Gradients and orientations.
- A HOG cell histogram with interpolated votes.
- L2-Hys normalisation.
- Lowe’s ratio test.
Practice.
- Use cv2.SIFT_create (patent expired in 2020) or ORB for speed; kornia.feature for differentiable and learned versions (DISK, LightGlue).
- Always follow matching with a geometric check (RANSAC on a homography or fundamental matrix) and report inlier counts.
- Use RootSIFT and mutual nearest neighbours as cheap improvements.
- For detection with HOG, use scikit-image hog and a linear SVM, with hard negative mining.
- For new projects, compare against a learned matcher (SuperPoint + LightGlue) on your own imagery; classical features still win on some domains and on tight compute.
import cv2, numpy as np
img1, img2 = (cv2.imread(f, cv2.IMREAD_GRAYSCALE) for f in ("pass_1.png", "pass_2.png"))
sift = cv2.SIFT_create(nfeatures=4000)
k1, d1 = sift.detectAndCompute(img1, None); k2, d2 = sift.detectAndCompute(img2, None)
pairs = cv2.BFMatcher(cv2.NORM_L2).knnMatch(d1, d2, k=2)
good = [m for m, n in pairs if m.distance < 0.8 * n.distance] # Lowe's ratio test
src = np.float32([k1[m.queryIdx].pt for m in good]); dst = np.float32([k2[m.trainIdx].pt for m in good])
H, inliers = cv2.findHomography(src, dst, cv2.USAC_MAGSAC, 3.0)
print(len(good), int(inliers.sum()))- 1. After ratio-test matching, always…
- 2. A cheap improvement to SIFT matching:
- 3. A modern learned matcher:
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why histograms of gradients. Gradient orientation is unchanged by adding a constant and by multiplying intensities, so normalised orientation histograms are invariant to affine lighting changes. Pooling over cells tolerates small shifts and deformations, and interpolated votes avoid jumps at bin boundaries. Clipping at 0.2 limits the influence of a few strong gradients, which change with non-linear lighting.
Rotation invariance. Rotating the image rotates every gradient and moves the patch content. If a reference orientation θ is measured in the patch and the descriptor is computed in a frame rotated by θ, the two effects cancel. The scheme is only as good as θ: when the orientation histogram has two similar peaks, noise can flip the choice and the descriptor changes completely, which is why SIFT duplicates keypoints with secondary peaks and why detectors favour well-structured points.
Scale. The scale-normalised Laplacian σ²∇²G has extrema at a scale proportional to the size of a blob (Lindeberg, 1998); the difference of Gaussians approximates it cheaply. Describing the patch at that scale gives scale invariance.
Ratio test. A correct match is usually much closer than the closest wrong candidate; for repeated texture several candidates are equally close, and the ratio d₁ / d₂ approaches 1. Thresholding it removes most false matches at a small loss of correct ones (Lowe reported eliminating 90% of false matches while discarding under 5% of correct ones at 0.8).
- 1. Gradient orientation is unchanged by…
- 2. Orientation normalisation fails when…
- 3. The difference of Gaussians approximates…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.What does each ingredient of a SIFT-like descriptor buy under rotation and lighting change, and what does invariance cost?
History.
- C. Harris and M. Stephens, “A combined corner and edge detector” (1988).
- D. Lowe, “Distinctive image features from scale-invariant keypoints” (2004; first version 1999).
- N. Dalal and B. Triggs, “Histograms of oriented gradients for human detection” (2005).
- E. Rublee et al., “ORB: an efficient alternative to SIFT or SURF” (2011); P. Lindenberger et al., “LightGlue” (2023).
Exercise 2. A 160 × 160 smooth random texture and 100 random keypoints. The second view rotates the image about its centre and applies an intensity change 0.5 I + 0.3, plus noise of standard deviation 0.01.
- Descriptors: raw 16 × 16 pixels; the same with zero mean and unit norm; an upright 4 × 4 × 8 gradient-histogram grid with L2-Hys; the same grid after SIFT orientation assignment (36-bin histogram, parabolic peak).
- Measure: nearest-neighbour accuracy among the 100 candidates; share kept and precision under the 0.8 ratio test.
| second view | raw pixels | normalised pixels | upright grid | SIFT-like |
|---|---|---|---|---|
| noise only | 1.0 | 1.0 | 1.0 | 0.93 |
| contrast and brightness | 1.0 | 1.0 | 1.0 | 0.92 |
| rotation 15° | 0.99 | 0.99 | 0.99 | 0.90 |
| rotation 30° | 0.28 | 0.13 | 0.16 | 0.86 |
| rotation 90° | 0.02 | 0.0 | 0.01 | 0.89 |
| rotation 30° and contrast | 0.27 | 0.13 | 0.15 | 0.84 |
- Pooling tolerates small rotations, not large ones: all upright descriptors handled 15° but collapsed at 30° (0.16 for the upright grid on all three seeds).
- Orientation normalisation gave rotation invariance: 0.89, 0.91 and 0.89 at 90° on seeds 0, 1 and 2. Ratio-test precision stayed at or above 0.965 for the SIFT-like descriptor in every condition and seed.
- A global contrast change did not break raw-pixel nearest neighbours here (accuracy 1.0), but made them far less distinctive: the ratio test kept only 0.91, 0.78 and 0.50 of raw-pixel matches on the three seeds against 1.0 for normalised descriptors.
- Invariance has a cost: with no transformation the SIFT-like descriptor found 0.93 (seeds 1 and 2: 0.88 and 0.93) instead of 1.0, because at random points the orientation histogram often has competing peaks. SIFT reduces this with detected keypoints and duplicate orientations, which this exercise omits.
- Caveat: synthetic texture, no scale change or perspective, random rather than detected keypoints.
Feature descriptors in AI, robotics and aerospace
- Planetary navigation: visual odometry on NASA’s Mars rovers tracks features between stereo frames; terrain-relative navigation matched landmarks to orbital maps during the Perseverance landing (2021).
- Earth observation: co-registration of Sentinel-2 and Landsat scenes and of multi-date drone imagery uses SIFT or learned matches with RANSAC.
- Robotics: ORB-SLAM3 and VINS-Fusion run binary features in real time; structure-from-motion pipelines such as COLMAP and GLOMAP default to SIFT, increasingly paired with learned matchers.
References
- D. G. Lowe (2004). “Distinctive image features from scale-invariant keypoints.” IJCV.
- N. Dalal and B. Triggs (2005). “Histograms of oriented gradients for human detection.” CVPR.
- C. Harris and M. Stephens (1988). “A combined corner and edge detector.” Alvey Vision Conference.
- E. Rublee, V. Rabaud, K. Konolige and G. Bradski (2011). “ORB: an efficient alternative to SIFT or SURF.” ICCV.
- D. DeTone, T. Malisiewicz and A. Rabinovich (2018). “SuperPoint: self-supervised interest point detection and description.” CVPR Workshops.
- P. Lindenberger, P.-E. Sarlin and M. Pollefeys (2023). “LightGlue: local feature matching at light speed.” ICCV.