Problemintro
Feature matching
Also called keypoint matching, descriptor matching.
Given the features of two images, find the pairs that show the same scene point, usually by nearest neighbors in descriptor space and a filter of the doubtful ones.
- Time
- O(m n D) worst
- Where
- D = the length of a descriptor; m = the number of features of the first image; n = the number of features of the second image
- Model
- Real RAM
Feature matching takes the features of two images, each a position and a descriptor, and returns pairs that show the same point of the scene. The true pairs are fixed by the geometry of the scene, which the matcher does not know, so in practice the problem is solved in two parts. First each feature gets candidates by nearest neighbor search in descriptor space. Then doubtful candidates are removed by filters such as Lowe's ratio test and the mutual check, and often by a geometric test with RANSAC. Exact search with brute force costs ; approximate search with a kd-forest is much faster for SIFT-sized descriptors. Learned matchers such as SuperGlue and LoFTR replace the hand-made filters with a network. Feature matching is the first step of image stitching, structure from motion and visual odometry.
In plain words
Take two photos of the same building from two places. A detector marks a few hundred small spots in each photo, such as corners of windows, and describes each spot by a list of numbers. Feature matching draws lines between spots of the two photos that show the same corner. The easy idea is to link each spot to the spot with the most similar numbers. That goes wrong when many windows look the same, or when a spot is hidden in the other photo, because a hidden spot still has some most similar spot. So matchers add checks: is the best partner clearly better than the second best, do the two spots pick each other, and do all lines agree with one camera motion?
Definition
Input. Two finite lists of features. The first image has features for , and the second has features for . Here are image positions and are descriptors. A distance on descriptors is given, usually the Euclidean distance, or the Hamming distance for binary descriptors.
Output. A set of pairs. Most methods return a partial matching: each and each is in at most one pair.
The goal. Let be the set of true pairs, those whose two features show the same scene point within a tolerance . For example, for a plane seen by two cameras, for a homography , where adds a coordinate 1 and divides by the last coordinate. The matcher does not know or the 3D scene, so is not a function of the input, and a matcher is judged by its precision and its recall on data with known geometry.
The computable versions. The following are exact problems with a unique answer once a tie rule is fixed, for example "the smaller index wins":
- Nearest neighbor matching: with . This is the bichromatic all nearest neighbors problem.
- Filtered matching: the pairs of nearest neighbor matching that pass a filter, such as , where is the distance to the second nearest neighbor, or , where is nearest neighbor matching in the other direction.
- Optimal partial assignment: a partial matching that maximizes for a value , the gain of a pair minus its distance. Pairs with never help, so features without a good partner stay unmatched.
The number of partial matchings is , so the optimization version cannot be solved by trying them all, except on tiny inputs.
Variants
- Sparse and dense. Sparse matching uses keypoints from a detector. Dense or detector-free matching, such as LoFTR, matches cells of a grid and refines the positions, which helps on surfaces with little texture.
- One-to-many. Keep the nearest neighbors of each feature, for example to give RANSAC more candidates. The result is not a matching.
- Guided matching. When a fundamental matrix or a homography is already known, search only near the epipolar line or the predicted position.
- Matching against a database. Match the features of one image against those of many images, as in image retrieval, where the features are often quantized into visual words.
- Binary descriptors. With ORB or BRIEF, the distance is the Hamming distance and hashing replaces kd-trees.
Examples
One-dimensional descriptors make a case that you can check by hand. Let , , and , , , , with . Suppose the true pairs are , and has no true partner.
| feature | nearest | second nearest | picked back? | |||
|---|---|---|---|---|---|---|
| 0.1 | 1.2 | 0.083 | yes | |||
| 0.2 | 0.22 | 0.909 | yes | |||
| 3.78 | 3.8 | 0.995 | no, picks |
| method | output | precision | recall |
|---|---|---|---|
| nearest neighbor | 2/3 | 1 | |
| ratio test, | 1 | 1/2 | |
| mutual check | 1 | 1 | |
| optimal partial assignment, | , gain | 1 | 1 |
| full assignment of minimum total distance | , total | 2/3 | 1 |
The ratio test drops the true pair , because and are almost equally close to : it cannot tell a repeated pattern from a true partner. The mutual check keeps and drops , because prefers . For the partial assignment, only the pairs , , and have and a positive gain; the best choice is with , since with gives only 1.68. A full assignment must use , so it adds the false pair . No method wins on every input; the table shows one input.
Known algorithms
- Brute force. Compute all distances: time, exact. On a GPU this is often the fastest choice for a few thousand features.
- kd-tree search. Exact nearest neighbors with the kd-tree search, fast in low dimension, but for it visits most of the leaves.
- Best bin first. Approximate search in one kd-tree that stops after a fixed number of leaves, which bounds the time per query; Lowe (2004) used it for SIFT.
- Randomized kd-forest. Several trees with random splits searched with one priority queue, a default of the FLANN library.
- Locality-sensitive hashing. Approximate search by hashing, common for binary descriptors.
- Filters. The ratio test and the mutual check cost one more nearest neighbor and one more search in the other direction. RootSIFT changes the descriptors before the search.
- Global assignment. The optimal partial assignment is a maximum weight matching in a bipartite graph and can be solved with the Hungarian algorithm in time.
- Learned matchers. SuperGlue refines the descriptors with attention and solves an entropic partial assignment with Sinkhorn iterations; LoFTR matches a coarse grid without a detector and refines each match in a window.
- Verification. RANSAC or PROSAC fits a homography or a fundamental matrix and keeps the pairs that agree with it, as in spatial verification.
| Algorithm | Time | Space | Properties | Code |
|---|---|---|---|---|
| BRIEF descriptor | O(W H + k d) worst · average · best | O(W H + k d / w) extra | deterministicexactheuristicnot rotation invariantnot scale invariant | 1 language |
| BRISK features | O(W H + n q) worst · average · best | O(W H + n) extra | deterministicnot exactheuristicrotation invariantscale invariant | 1 language |
| DAISY descriptor | O(W H B Q (R + T)) worst · average · best | O(W H B Q) extra | densedeterministicexactnot rotation invariant | 1 language |
| KAZE features | O(N W H + n) worst · average · best | O(N W H + n) extra | deterministicnot exactheuristicrotation invariantscale invariant | 1 language |
| LoFTR | O(M N d + K w^2 d) worst · average · best | O(M N + w^2) extra | detector freedeterministiclearnednetwork cost excludedsubpixelsymmetric coarse matches | 1 language |
| ORB features | O(W H log(W H) + n m) worst · average | O(W H + n m) extra | deterministicnot exactheuristicrotation invariantnot scale invariant | 1 language |
| SuperGlue | O(T M N) worst · average · best | O(M N) extra | deterministiclearnednetwork cost excludedpartial assignmentsymmetric | 1 language |
| Speeded up robust features | O(W H + n) worst · average · best | O(W H + n) extra | deterministicnot exactheuristicrotation invariantscale invariant | 1 language |
Bounds
In the real RAM with cost per arithmetic operation, brute force gives for nearest neighbor matching and for both filters. Every exact method must read the input, so is a trivial lower bound. In fixed low dimension, kd-trees and other point location structures answer each query in about logarithmic time on typical data, but descriptors have from 32 to 256. For such dimensions, results of fine-grained complexity under the Strong Exponential Time Hypothesis indicate that the exact bichromatic closest pair problem, and so also exact nearest neighbor matching, has no algorithm that is much faster than when grows like . This is why practical matchers use approximate search.
The goal has a different limit, which is not about time. Two scene points with equal descriptors give the same input whichever of them is the true partner, so no method that uses only the descriptors can be correct on both. Filters reduce this risk by dropping such features; geometry, as in RANSAC, or context, as in SuperGlue, can resolve it. Precision and recall of real methods are measured on benchmarks, not proved.
Reductions
- To nearest neighbor search. Nearest neighbor matching is queries of nearest neighbor search against points, plus the cost to build the index. The ratio test needs two nearest neighbors per query, and the mutual check needs more queries in the other direction.
- From bichromatic closest pair. The closest pair between the two lists is the nearest neighbor pair of smallest distance, which takes more time. So a fast exact matcher gives a fast exact bichromatic closest pair algorithm, which is the reason for the bound above.
- To the assignment problem. Add a dummy partner for each feature with gain 0. The optimal partial assignment becomes an assignment problem on rows and columns.
Applications
- Image stitching and homography estimation from matched points.
- Structure from motion, where matches are chained into feature tracks, and the relative pose problem with the essential matrix.
- Visual odometry and localization of a camera in a known map.
- Image retrieval and visual place recognition, with matching as the spatial verification of the best results.
References
- Richard Szeliski, Computer Vision: Algorithms and Applications, 2nd edition, Springer, 2022, Section 7.1.3, feature matching: matching strategies and error rates, efficient matching, and feature match verification
- David G. Lowe, Distinctive image features from scale-invariant keypoints, International Journal of Computer Vision 60(2), 2004, 91-110, Section 7, keypoint matching with the ratio of the two nearest distances, approximate search with best bin first, and verification by a pose
- Marius Muja and David G. Lowe, Scalable nearest neighbor algorithms for high dimensional data, IEEE Transactions on Pattern Analysis and Machine Intelligence 36(11), 2014, 2227-2240, the approximate nearest neighbor methods for descriptor matching and their measured speed and precision
- Paul-Edouard Sarlin, Daniel DeTone, Tomasz Malisiewicz and Andrew Rabinovich, SuperGlue, learning feature matching with graph neural networks, IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2020, the formulation of matching as a partial assignment with a dustbin for unmatched features
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag F0B3WT Edit this page History Report an error Markdown