RANSAC | VitaVision
Back to atlas

RANSAC

13 min readIntermediateView in graph

Definition

Random Sample Consensus (RANSAC) is a meta-algorithm for fitting a parametric model to data that contains an unknown fraction of gross errors (outliers). A minimal random subset of ss data points is drawn, a model is instantiated from it, and the size of the globally consistent subset — the consensus set — is measured. Iteration continues until a consensus set of sufficient size is found or a trial budget is exhausted.

The required number of trials to guarantee, with probability pp, that at least one drawn sample is outlier-free is:

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

where ss is the minimal sample size (the number of points required to instantiate the model), ww is the inlier ratio (the fraction of data points consistent with the true model to within tolerance ε\varepsilon), and pp is the desired success probability (typically 0.95 or 0.99).

Decision table

The RANSAC family is alive in three forms, each a different point in the design-axis space defined in the next section. Author choice is per-problem, not historical.

Fischler–Bolles 1981 USAC 2013 MAGSAC 2019
Sampler uniform random PROSAC (quality-ordered) uniform / Progressive NAPSAC
Verifier full consensus count SPRT early reject (Λj>A\Lambda_j > A) σ\sigma-loop with SPRT pre-screen
Local optimisation optional least-squares re-fit inner-RANSAC / Lo-RANSAC (10102020 iters) IRLS on marginal-likelihood weights
Inlier threshold fixed scalar ε\varepsilon fixed scalar ε\varepsilon marginalised σ[0,σmax]\sigma \in [0, \sigma_\mathrm{max}]
Degeneracy handling not bundled DEGENSAC for fundamental matrix inherited from underlying solver
Best for foundational baseline; teaching; problems with clean ε\varepsilon tune speed-critical pipelines; fundamental-matrix with planar degeneracy scenes with unknown or scene-varying noise scale; geometric accuracy on real data

For the per-pair tradeoff between USAC and MAGSAC, see the When to choose USAC over MAGSAC section on the USAC page (hosted there per the older + broader-scope tiebreaker).

Mathematical Description

Iteration count

The derivation follows from the geometric series identity. The probability that a single draw of ss points is all-inlier is wsw^s. The probability that all NN draws fail is (1ws)N(1 - w^s)^N. Setting 1(1ws)Np1 - (1 - w^s)^N \geq p and solving for NN gives the formula above.

The expected number of trials before the first all-inlier draw is

E[k]=ws,E[k] = w^{-s},

and the standard deviation is

SD(k)=1wsws.\mathrm{SD}(k) = \frac{\sqrt{1 - w^s}}{w^s}.

For small wsw^s, SD(k)E[k]\mathrm{SD}(k) \approx E[k]: the distribution of trials-to-success has a fat tail. Setting N=E[k]N = E[k] yields only approximately 63% success probability; p=0.99p = 0.99 requires N4.6×E[k]N \approx 4.6 \times E[k] in the worst case. For p=0.99p = 0.99, w=0.5w = 0.5, s=4s = 4: N72N \approx 72, with E[k]=16E[k] = 16.

The three free parameters governing a RANSAC run are ε\varepsilon (the inlier-distance threshold), NN (the number of trials, set via the formula above), and tt (the minimum consensus-set size required for acceptance). The acceptance threshold is set so that ts=5t - s = 5 when the probability of an outlier lying within ε\varepsilon of an incorrect model is below 0.5; this gives greater than 95% probability of rejecting an incorrect model.

The four design axes of practical RANSAC

Sampling. The founding paper draws each minimal sample uniformly at random from the full data set. Subsequent variants exploit external quality signals. PROSAC sorts data points by a quality score (e.g., feature-match similarity) and draws progressively from the top-ranked subset, expanding toward the full set after TNT_N total draws; this produces all-inlier samples far earlier in the sequence while retaining the same asymptotic guarantees. NAPSAC biases sampling toward spatially proximate points. Progressive NAPSAC combines quality ordering with spatial proximity. USAC-1.0 uses PROSAC as its default sampler; the sampling stage is independently swappable.

Model verification. Standard RANSAC evaluates all NN data points against each candidate model. R-RANSAC with SPRT (Sequential Probability Ratio Test) accumulates the likelihood ratio

Λj=r=1jp(xrHb)p(xrHg),\Lambda_j = \prod_{r=1}^{j} \frac{p(x_r \mid H_b)}{p(x_r \mid H_g)},

where HgH_g is the hypothesis that the current model is correct (inlier probability ε\approx \varepsilon) and HbH_b is the hypothesis that it is not (inlier probability δ\delta). When Λj\Lambda_j exceeds a decision threshold AA derived from the acceptable type-I error α\alpha and type-II error β\beta, the model is rejected early without evaluating the remaining points. SPRT achieves a 2–9× runtime improvement over standard verification on homography and fundamental-matrix benchmarks. USAC-1.0 reuses SPRT; MAGSAC also reuses it as a pre-screen.

Local optimisation. The founding paper optionally re-fits the model by least squares on the accepted consensus set; the quality of the re-fit depends on the consensus set size. LO-RANSAC applies inner-RANSAC within each accepted hypothesis: nonminimal samples are drawn from the current inlier set, each candidate is refined by iteratively reweighted least squares, and the best result is retained. USAC-1.0 implements local optimisation as an outer-stage block, running 10–20 inner iterations with an early exit when the inlier set overlaps the previous best by ≥95%. Local optimisation reduces the number of required outer iterations by a factor of 2–3.

Inlier-threshold treatment. The founding paper uses a fixed scalar ε\varepsilon: each point is classified as inlier if its residual dist(p,M)ε\mathrm{dist}(p, M) \leq \varepsilon and outlier otherwise. This hard boundary is sensitive to threshold calibration and to scene-to-scene variation in noise scale σ\sigma. MAGSAC eliminates the fixed threshold by treating σ\sigma as a random variable with a uniform prior on [0,σmax][0, \sigma_\mathrm{max}] and marginalising the RANSAC quality function over it:

Q(θ,P)=1σmax0σmaxQ(θ,σ,P)dσ.Q^*(\theta, P) = \frac{1}{\sigma_\mathrm{max}} \int_0^{\sigma_\mathrm{max}} Q(\theta, \sigma, P)\, d\sigma.

Per-point weights L(pθ)L(p \mid \theta) are the marginalised inlier likelihoods; the final model is a weighted least-squares fit with those weights (σ\sigma-consensus). The σ\sigma range is discretised into d=10d = 10 uniform partitions, reducing cost from O(K)O(K) to O(d)O(d) model re-fits per hypothesis. For χ2(4)\chi^2(4) residuals (2D point correspondences), the effective inlier threshold at each σi\sigma_i is τ(σi)=3.64σi\tau(\sigma_i) = 3.64\,\sigma_i.

Numerical Concerns

  • Exponential growth of NN in 1/w1/w. The iteration count N=log(1p)/log(1ws)N = \log(1-p) / \log(1 - w^s) is exponentially sensitive to the inlier ratio ww and the minimal sample size ss. For s=4s = 4, halving ww from 0.5 to 0.25 drives E[k]E[k] from 16 to 256. At w=0.2w = 0.2, s=4s = 4: E[k]=625E[k] = 625, rendering the algorithm impractical in real time without guided sampling such as PROSAC. A 0.1 under-estimate of ww from 0.5 to 0.4 at s=4s = 4 already doubles E[k]E[k] from 16 to 39.
  • Inlier-threshold calibration. The hard threshold ε\varepsilon mediates the signal-to-noise boundary. Too small an ε\varepsilon misclassifies genuine inliers, shrinking consensus sets below tt and causing false failure. Too large an ε\varepsilon admits outliers into the consensus set, corrupting the re-fit. The founding paper recommends setting ε\varepsilon to 1–2 standard deviations of the measurement noise; for 2D symmetric transfer error with Gaussian noise σ1px\sigma \approx 1\,\mathrm{px}, the chi-square inversion gives t2.45pxt \approx 2.45\,\mathrm{px}. A 2×2\times error in σ\sigma propagates to a 4×4\times change in t2t^2, suppressing or inflating the inlier count dramatically.
  • Degenerate minimal samples. If the ss randomly drawn points are in a degenerate configuration (e.g., four collinear points when fitting a homography, or five correspondences on a common 3D plane when fitting the fundamental matrix), the instantiated model is ill-defined or rank-deficient. The founding paper does not include a degeneracy rejection step; practitioners must add this guard. USAC-1.0 includes DEGENSAC, which detects when ≥ 5 of the 7 correspondences in a fundamental-matrix minimal sample are related by a homography and applies a model-completion step.
  • Fat-tailed convergence distribution. Because SD(k)E[k]\mathrm{SD}(k) \approx E[k] for small wsw^s, the actual number of trials to success can be many times the expected value. Setting N=E[k]N = E[k] yields only approximately 63% success probability. Production implementations should budget at least 335×E[k]5\times E[k] trials.
  • SPRT verifier sensitivity. The SPRT decision threshold AA is derived from the type-I error rate α\alpha and type-II error rate β\beta. If δ\delta — the probability of a random point fitting an incorrect model — is over-estimated, AA is set too low, causing premature rejection of correct hypotheses and degrading the stopping criterion. The online update in USAC-1.0 partly corrects mis-specified initial δ\delta, but early iterations accumulate stopping-criterion error. The nonrandomness significance level γ=0.05\gamma = 0.05 used in USAC-1.0's stopping-criterion computation is a hard-coded constant; tightening to 0.01 requires more samples.
  • Discretisation step in MAGSAC. The σ\sigma-consensus integral is approximated over d=10d = 10 uniform partitions of [0,σmax][0, \sigma_\mathrm{max}]. For σmax=10\sigma_\mathrm{max} = 10 pixels the first partition boundary is 1 px, matching the SPRT pre-screen reference threshold τref=1\tau_\mathrm{ref} = 1 pixel. Values of dd below 5 may underweight high-σ\sigma components. The integrand involves exp(D2/2σi2)\exp(-D^2 / 2\sigma_i^2), which underflows in float32 when D2/2σi2>88D^2/2\sigma_i^2 > {\sim}88; for σi=σmax/10=1px\sigma_i = \sigma_\mathrm{max}/10 = 1\,\mathrm{px} this occurs at D>13pxD > {\sim}13\,\mathrm{px}, safely beyond the τ(σmax)\tau(\sigma_\mathrm{max}) gate, so float32 is workable.

Where it appears

RANSAC underpins every estimation step in the atlas where correspondences may contain outliers.

Two-view geometry estimation. homography and epipolar-geometry describe models estimated from point correspondences; RANSAC is the standard outer loop for both. fundamental-matrix-eight-point uses RANSAC with the 8-point (or 7-point) minimal solver to reject wrong matches. dlt-normalisation documents the linear solver that RANSAC calls per hypothesis.

Camera calibration. zhang-planar-calibration uses RANSAC to reject corner detections that are inconsistent with the estimated homography per view. tsai-lenz-handeye and daniilidis-dual-quaternion-handeye both depend on robust estimation from correspondences that may include outlier motions.

Image stitching. apap-image-stitching, gao-dual-homography-stitching, lin-sva-stitching, and spatially-varying-image-stitching all use RANSAC to estimate a global or multi-model homography from feature matches before applying spatially-varying refinement.

Other. chessboard-x-corner-detection applies RANSAC to enforce grid consistency on detected corners. scale-space is a prerequisite for the feature detectors whose outputs feed RANSAC as correspondences. kumar-generalized-rac uses RANSAC in its outlier-filtering step. The deep-learning model pages ccdn-checkerboard-detector, ccs-camera-calibration, and mate-checkerboard-detector all compare their accuracy against classical baselines that use RANSAC as the robust estimator.

Surveyed methods

The three methods that anchor the design space have dedicated algorithm pages:

  • fischler-bolles-ransac — the founding paradigm: uniform sampling, full-consensus verification, optional least-squares re-fit, fixed scalar threshold ε\varepsilon. CACM, 1981.
  • raguram-usac — the unifying engineering framework: PROSAC sampler, SPRT verifier, Lo-RANSAC inner loop, DEGENSAC degeneracy module, fixed scalar threshold ε\varepsilon. PAMI, 2013.
  • barath-magsac — sigma-consensus: marginalises the inlier threshold over a noise-scale prior, IRLS-refits the model on per-point marginal-likelihood weights. CVPR, 2019.

The decision table at the top of this page summarises their per-axis choices; the per-pair tradeoff is captured in raguram-usac#when-to-choose-usac-over-magsac.

References

  1. M. A. Fischler, R. C. Bolles. Random Sample Consensus: A Paradigm for Model Fitting with Applications to Image Analysis and Automated Cartography. Communications of the ACM, 1981. dl.acm.org
  2. R. Raguram, O. Chum, M. Pollefeys, J. Matas, J.-M. Frahm. USAC: A Universal Framework for Random Sample Consensus. IEEE TPAMI, 2013. ieeexplore.ieee.org
  3. D. Barath, J. Matas, J. Noskova. MAGSAC: Marginalizing Sample Consensus. CVPR, 2019. arxiv.org