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

  1. Draw a minimal sample SS of ss correspondences uniformly at random (ss = 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).
  2. Fit the model θS\theta_S to the sample.
  3. Count inliers: data points consistent with θS\theta_S within an error threshold ϵ\epsilon (e.g., Sampson distance or reprojection error of a few pixels).
  4. Repeat for NN iterations; keep the model with the largest inlier set.
  5. 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 ww be the inlier ratio. The probability that one sample of ss points is all-inlier is wsw^s, so the probability that at least one of NN samples is all-inlier is

P(success)=1(1ws)NP(\text{success}) = 1 - (1 - w^s)^N

Requiring P(success)1ηP(\text{success}) \geq 1 - \eta (e.g., η=0.01\eta = 0.01 for 99% confidence) gives

N=logηlog(1ws)N = \frac{\log \eta}{\log(1 - w^s)}

Examples at w=0.5w = 0.5, η=0.01\eta = 0.01:

SolverssNN
5-point essential matrix5145\approx 145
8-point fundamental matrix81177\approx 1177

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 NN in advance: it re-estimates ww from the best inlier set found so far, recomputes NN, and terminates early once enough samples have been drawn for the current estimate — usually far fewer iterations in easy scenes.

Practical notes

Why it matters for SLAM

Hands-on