RANSAC
RANSAC (Random Sample Consensus), introduced by Fischler & Bolles in 1981, is the dominant robust estimation method in SLAM and multi-view geometry. It fits a parametric model (essential matrix, homography, camera pose, plane, …) to data contaminated by outliers — false feature matches, occlusions, moving objects — by repeatedly hypothesizing models from small random samples and scoring them by consensus.
Algorithm
- Draw a minimal sample of correspondences uniformly at random ( = smallest number that determines the model: 5 points for the essential matrix, 4 for a homography, 3 for P3P, 8 for the fundamental matrix with the linear 8-point algorithm).
- Fit the model to the sample.
- Count inliers: data points consistent with within an error threshold (e.g., Sampson distance or reprojection error of a few pixels).
- Repeat for iterations; keep the model with the largest inlier set.
- Optionally refit the model to all inliers by least squares (and often iterate the refit).
The key insight: even with 50% outliers, a small all-inlier sample is drawn with reasonable probability after enough tries, and the correct model gathers far more consensus than models fit to contaminated samples.
How many iterations?
Let be the inlier ratio. The probability that one sample of points is all-inlier is , so the probability that at least one of samples is all-inlier is
Requiring (e.g., for 99% confidence) gives
Examples at , :
| Solver | ||
|---|---|---|
| 5-point essential matrix | 5 | |
| 8-point fundamental matrix | 8 |
The iteration count grows exponentially in the sample size — this is exactly why minimal solvers (5-point E, P3P) are preferred inside RANSAC over larger linear solvers.
Adaptive RANSAC does not fix in advance: it re-estimates from the best inlier set found so far, recomputes , and terminates early once enough samples have been drawn for the current estimate — usually far fewer iterations in easy scenes.
Practical notes
- The threshold should reflect the measurement noise (pixels); too tight rejects good data, too loose admits outliers.
- Degenerate samples (collinear/coplanar points for some models) must be detected and re-drawn.
- Variants: PROSAC (samples quality-ranked matches first), LO-RANSAC (local optimization of promising models), MLESAC (scores by likelihood instead of inlier count), and globally optimal alternatives such as MaxCon consensus maximization.
- After RANSAC, remaining small errors are handled by M-estimators / robust kernels inside the nonlinear refinement.
Why it matters for SLAM
- Every geometric estimation step in a feature-based pipeline runs inside RANSAC: essential/fundamental matrix for initialization and 2D–2D motion, homography for planar scenes, PnP for tracking and relocalization, ICP correspondence pruning, and loop-closure verification.
- Descriptor matching alone routinely produces 20–50% wrong matches; without RANSAC the least-squares estimates would be arbitrarily corrupted (least squares has zero breakdown tolerance to outliers).
- Loop-closure candidates from place recognition are geometrically verified with RANSAC before being added to the pose graph — a single false loop constraint can destroy the whole map.