TL;DR
Feature matching takes the descriptors from two images and pairs each descriptor with its most similar partner in the other image. Most of those pairs are wrong, so the pairs are filtered twice: first by a ratio test and mutual agreement on descriptor distance, then by fitting a geometric model with RANSAC and keeping only the pairs that agree with it. What survives is a set of correspondences between the two images.
Where you'll see it: the first step of structure-from-motion, where correspondences between photos are triangulated into 3D points, and image stitching, where they define how one photo overlaps the next.
Intuition
Local features give you two bags of descriptors, one per image. Matching asks: which point in image B is the same physical point as this point in image A? Descriptors that look alike are candidates, so the natural first answer is the nearest one in descriptor space.
That answer is noisy. A repeated window on a building front gives many descriptors that look alike, and some points visible in A are not visible in B at all. So the nearest neighbour is often a wrong point that happens to look similar. The fix is to demand more evidence than "closest". A match should be clearly better than the alternatives, and it should agree with the geometry of the scene: if two points really are the same, the way the two images are related must map one onto the other.
The first filter uses only descriptors. The second uses the fact that a camera pair imposes rules on where matches can lie. Because some matches are still wrong, a robust fitting method is used rather than least squares.
flowchart LR A[Descriptors in image A] --> N[Nearest neighbour<br/>in image B] N --> R[Ratio test<br/>and mutual check] R --> G[Fit a geometric model<br/>with RANSAC] G --> C[Inlier correspondences]
The math
Nearest neighbour
Let be a descriptor in image A and the descriptors in image B. The nearest neighbour is
where is the Euclidean distance. The index is the candidate match. Finding it exactly means comparing against every descriptor in B, which is linear in the number of points. Approximate search structures, covered in Approximate Nearest Neighbor Search, trade a small chance of missing the true nearest neighbour for a large speedup.
Ratio test
Let be the distances from to its two nearest neighbours in B. Accept the match only when
with around 0.8. The reason is that a correct match is typically much closer than any wrong one, so its ratio is small. A repeated structure gives two almost equally close candidates, a ratio near 1, and the test rejects it. Lowe introduced this test in the SIFT paper.
Mutual check
Also search in the other direction: find the nearest neighbour in A for each . Keep a pair only if each point is the other's nearest neighbour. This is a cheap way to remove many-to-one assignments.
Geometric verification with RANSAC
The surviving pairs still contain outliers. Suppose the scene is roughly planar, or the two views differ by a pure rotation, so the relation between the images is a homography, a 3 by 3 matrix with in homogeneous coordinates. For a general scene with a moving camera the right model is the fundamental matrix from Epipolar Geometry, which satisfies for each true match.
A least-squares fit to all pairs would be pulled off by the outliers. RANSAC (random sample consensus, Fischler and Bolles, 1981) avoids this:
- Draw a minimal sample of pairs. The minimum is 4 for a homography and 8 for the eight-point method for .
- Fit the model to the sample.
- Count the inliers: pairs whose residual is below a threshold .
- Keep the model with the most inliers, and refit to all of them.
The number of random draws needed to find an all-inlier sample with probability depends on the inlier ratio :
With , a low inlier ratio drives up quickly, because the chance that a random sample is all inliers is .
Worked examples
Take , a homography with , and an inlier ratio . These numbers are illustrative.
- Chance that one sample of 4 is all inliers: .
- Chance that one sample is not all inliers: .
- .
- .
- , so draw 72 samples.
Now the same scene with .
- , so .
- , so draw 9 samples.
Interpretation: a drop in inlier ratio from 0.8 to 0.5 multiplies the work by about eight, which is why the descriptor-level filters matter. Each outlier removed earlier makes the geometric step cheaper.
Image A has descriptors and . Image B has and . Distances (illustrative):
| 0.20 | 0.50 | |
| 0.31 | 0.33 |
- For : , , ratio . Below 0.8, candidate .
- For : , , ratio . Above 0.8, rejected as ambiguous.
- Mutual check on : the nearest neighbour of in A is (distance 0.20 against 0.31 for ). The pair survives.
Interpretation: looks like both and equally well, so no match is safe. The ratio test rejects it without any geometry.
Tradeoffs and failure modes
| Situation | Problem | Better choice |
|---|---|---|
| Repeated texture or symmetric structure | Ambiguous nearest neighbours | Stricter ratio, then geometric verification |
| Wide baseline or large viewpoint change | Few correct initial pairs, low inlier ratio | Affine-invariant features, or learned matchers |
| Scene that is nearly planar | Fundamental matrix is poorly constrained | Use a homography model |
| Many thousands of descriptors | Exact matching is slow | Approximate nearest-neighbour search |
| Very low inlier ratio | RANSAC needs huge iteration counts | Better descriptors, or prior information about motion |
A correspondence can be wrong and still look good under the descriptor test, if the scene has a repeated pattern. Geometric verification is what catches that, but only if the model is correct for the scene. If the wrong model is fitted, RANSAC will confidently keep the wrong matches.
History
Nearest-neighbour matching with descriptors became standard after Lowe's 2004 SIFT paper, which introduced the ratio test in the form used here. RANSAC was introduced by Fischler and Bolles in 1981 for fitting models in the presence of gross outliers, and it became a standard tool for geometric verification in structure from motion and panorama stitching. The combination of descriptor matching plus RANSAC is the standard recipe still used in most classical pipelines.
Check yourself
QuestionWhy does the ratio test reject a match whose two nearest neighbours are almost equally close, even when the nearest one is the correct point?Show answer
If the second-nearest neighbour is almost as close, the descriptor alone cannot tell the candidates apart, and a wrong point could be the true one. A correct match in a distinctive region typically has a clearly smaller distance than any alternative, so its ratio is small. The test accepts only those, so the rejected cases are those where the data gives no clear winner. Some correct matches are lost, but the surviving set has far fewer wrong ones.
QuestionWith and , compute the number of RANSAC samples for an inlier ratio of 0.8.Show answer
Compute . Then and . With , , so draw 26 samples. The eight-point method needs eight pairs per sample, so each draw is more expensive, and this is why the homography case with four pairs is often preferred when the scene allows it.
QuestionWhy is a least-squares fit to all candidate correspondences a bad way to verify geometry?Show answer
Least squares minimises the total squared residual, so a few large residuals from wrong matches pull the fitted model toward them. The fit then serves none of the matches well. RANSAC instead fits to small random samples and scores each model by its inlier count, so the wrong matches do not influence the chosen model. The final refit uses only the inliers, which is when least squares is appropriate.
QuestionYou run feature matching on two photos of a flat facade taken from one side of the building. Which geometric model would you fit, and what would you expect the inlier count to show?Show answer
A flat facade seen from different positions is related by a homography, so fitting with four-point samples is appropriate. A fundamental matrix can also be fitted to planar points, but many matrices then explain the same matches, so the fit is not well determined. If the inlier count is much lower than the number of matches that look correct, either the threshold is too tight for the image resolution, or the surface is not as planar as assumed, which means the homography is the wrong model.
QuestionWhy does the mutual check catch some errors that the ratio test misses?Show answer
The ratio test looks only at the distances from one descriptor in A to its neighbours in B. Two descriptors in A can both pick the same descriptor in B, which the ratio test does not see because each choice looks clear from A's side. The mutual check asks whether the choice holds in the other direction, so a many-to-one assignment fails it for at least one of the two points.
Sources
- Fischler and Bolles (1981). Random Sample Consensus: A Paradigm for Model Fitting. Random sample consensus
- Lowe (2004). Distinctive Image Features from Scale-Invariant Keypoints. DOI