Locally Optimized RANSAC (LO-RANSAC) | VitaVision
← Back to atlas

Locally Optimized RANSAC (LO-RANSAC)

7 min readIntermediateView in graphIn narrative: Forty Years Against Outliers
Based on
Locally Optimized RANSAC
Chum, Matas, Kittler · DAGM 2003 (Lecture Notes in Computer Science) 2003
DOI ↗

Goal

Reduce the number of samples RANSAC needs to reach a given confidence, and improve the quality of the returned model, by correcting the assumption underlying the standard termination criterion — that a model instantiated from one outlier-free minimal sample is consistent with the entire inlier set. Input: NN correspondences, minimal sample size mm, inlier threshold θ\theta. Output: model parameters and the achieved inlier set, reached with the same termination guarantee as standard RANSAC but in measurably fewer trials, using no additional input information beyond what standard RANSAC requires.

Algorithm

Let η\eta denote the probability of having missed the full inlier set after kk samples. Let PIP_I denote the probability that an mm-point minimal sample is entirely outlier-free, and ε=I/N\varepsilon = I/N the inlier fraction. Let θ\theta denote the inlier-distance threshold and KK a threshold multiplier used by the iterative local-optimization variant. Let IkI_k denote the inlier count of the kk-th sampled hypothesis.

Definition
Standard termination criterion
η=(1−PI)k,PI=(Im)/(Nm)≈εm.\eta = (1 - P_I)^k, \qquad P_I = \binom{I}{m}\Big/\binom{N}{m} \approx \varepsilon^m.

This implicitly assumes a model fit from one uncontaminated minimal sample is consistent with all II inliers — an assumption that "rarely holds in practice," since minimal-sample model estimates are themselves noisy.

Definition
Local-optimization invocation bound

The per-sample inlier count behaves as a random variable whose kk-th draw has probability 1/k1/k of being a new running maximum, so the expected number of new-maximum events (hence local-optimization invocations) within kk samples is bounded by

∑i=1k1i≤log⁡k+1,\sum_{i=1}^{k} \frac{1}{i} \le \log k + 1,

i.e. local optimization runs O(log⁡k)O(\log k) times over a full run — asymptotically negligible against kk total samples.

Procedure

Algorithm
LO-RANSAC
Input: Data set with NN correspondences; minimal sample size mm; inlier threshold θ\theta; target miss probability η\eta.
Output: Model parameters θ∗\theta^* and inlier set I∗I^*, reached in fewer samples than standard RANSAC for the same η\eta.
  1. Draw a minimal sample SmS_m of size mm and estimate model parameters from it.
  2. Count inliers IkI_k under threshold θ\theta.
  3. If IkI_k exceeds every previous IjI_j (j<kj < k), run a local optimization step and retain the result only if it improves on the current best.
  4. Recompute η\eta via the standard termination criterion; repeat from step 1 until η\eta falls below the target.

Five local-optimization variants are compared for step 3:

  1. Standard — no local optimization (baseline RANSAC).
  2. Simple — collect all points with error below θ\theta under the minimal-sample model and re-fit by a non-minimal linear algorithm.
  3. Iterative — collect points with error below KθK\theta (a looser threshold), re-fit, then shrink the threshold toward θ\theta and repeat. Restricting the first re-fit to points already close to a sample-consistent model excludes leverage points that would otherwise corrupt a naive iteratively-reweighted least-squares pass over the whole data set.
  4. Inner RANSAC — run a fresh, smaller RANSAC restricted to the IkI_k inlier points of the current best model, drawing non-minimal inner samples of size min⁡(Ik/2,14)\min(I_k/2, 14) for epipolar geometry or min⁡(Ik/2,12)\min(I_k/2, 12) for homography, repeated 10 times, and verified against the full data set.
  5. Inner RANSAC with iteration — method 4, with each inner-RANSAC sample additionally refined by method 3's threshold-shrinking re-fit.

Implementation

The outer loop with a pluggable local-optimization hook, implementing method 5 (Inner RANSAC with iteration), in Rust:

pub trait LocalOptimizer<M, P> {
    /// Draw a non-minimal inner sample from `inliers`, refit, and shrink
    /// the acceptance threshold toward `theta` across `rounds` passes.
    fn refine(&self, model: &M, points: &[P], inliers: &[usize], theta: f64) -> Option<M>;
}

/// One outer LO-RANSAC iteration: fit a minimal-sample model, count inliers,
/// and run local optimization when a new best is found (Algorithm 1, §2).
pub fn lo_ransac_step<M, P, L: LocalOptimizer<M, P>>(
    sample_model: M,
    points: &[P],
    theta: f64,
    residual: impl Fn(&M, &P) -> f64,
    best_inliers: usize,
    optimizer: &L,
) -> Option<(M, Vec<usize>)> {
    let inliers: Vec<usize> = points
        .iter()
        .enumerate()
        .filter(|(_, p)| residual(&sample_model, p) <= theta)
        .map(|(i, _)| i)
        .collect();

    if inliers.len() <= best_inliers {
        return None; // not a new best; no local optimization invoked
    }

    // New best: invoke local optimization (bounded to O(log k) calls per run).
    let refined = optimizer
        .refine(&sample_model, points, &inliers, theta)
        .unwrap_or(sample_model);
    Some((refined, inliers))
}

Remarks

  • Reported speed-up is "two to three fold" with 10–20% more inliers than standard RANSAC across five two-view-geometry experiments.
  • Method 5's efficiency ratio (actual samples over the theoretically expected count) is close to 1.0 — for example 1.01 on one experiment and 1.16 on another — against standard RANSAC's 2.63–3.35 on the same experiments.
  • Local optimization is invoked at most O(log⁡k)O(\log k) times per run; the empirical invocation count stays below the log⁡k\log k bound across all tested experiments and methods.
  • Non-iterative re-fitting alone (methods 2 and 4) underperforms its iterative counterpart (methods 3 and 5, respectively) with no compensating time saving.
  • Method 5's inner resampling is a liability when the inlier fraction is high and the total correspondence count is low, since resampling cost then dominates; method 3 was faster in that regime in one of the five reported experiments.
  • The modification "makes no new assumptions about the data" and is explicitly compatible with (not competing against) other RANSAC extensions such as MLESAC, R-RANSAC, and NAPSAC; see ransac for the four design axes that organise the modern RANSAC family. USAC incorporates LO-RANSAC's local optimization as its pluggable stage-4 module (see raguram-usac).

When to choose LO-RANSAC over MAGSAC

MAGSAC removes the need to tune a fixed inlier threshold θ\theta by marginalising the RANSAC quality function over an unknown noise scale σ∈[0,σmax]\sigma \in [0, \sigma_\mathrm{max}], at the cost of d=10d = 10 per-hypothesis model re-fits in its σ\sigma-consensus loop. LO-RANSAC keeps a fixed, user-supplied threshold θ\theta and instead spends its extra cost on at most O(log⁡k)O(\log k) local-optimization refits per run. MAGSAC's own applicability note names LO-RANSAC directly as the faster alternative "for tight-threshold well-calibrated setups" and reports it is the slowest method of those compared when the noise level is low (σ<0.3\sigma < 0.3 px), because σ\sigma-consensus runs on every minimal-sample model rather than only the current best.

LO-RANSAC MAGSAC
Inlier threshold fixed, user-supplied θ\theta marginalised over σ∈[0,σmax]\sigma \in [0, \sigma_\mathrm{max}], no fixed threshold
Extra per-run cost O(log⁡k)O(\log k) local-optimization invocations O(d)=O(10)O(d)=O(10) model re-fits per sampled hypothesis
Best regime (per MAGSAC's own comparison) well-calibrated threshold, tight compute budget, easy (low-noise) scenes unknown or scene-varying noise scale; high outlier ratio
Final refit least-squares or IRWLS re-fit on a non-minimal sample weighted least squares (IRLS) on marginal-likelihood weights
Direct empirical comparison included as a baseline in MAGSAC's own benchmark table wins average error on most of the compared dataset blocks; third on one block by a 0.03 px margin

Choose LO-RANSAC when the inlier threshold is well-calibrated for the imagery and stable across the dataset, when the scene noise level is low enough that σ\sigma-consensus's per-hypothesis overhead is not worth paying, or when no extra input beyond a single scalar threshold is available to tune. Choose MAGSAC when the inlier threshold is unknown or varies scene-to-scene, when geometric accuracy on real data is the primary metric, or when the outlier ratio is high enough that σ\sigma-consensus's iteration-count reduction outweighs its per-hypothesis cost.

References

  1. O. Chum, J. Matas, J. Kittler. Locally Optimized RANSAC. DAGM 2003 (Lecture Notes in Computer Science). PDF
  2. 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
  3. 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
  4. D. Barath, J. Matas, J. Noskova. MAGSAC: Marginalizing Sample Consensus. CVPR, 2019. arxiv.org

Prerequisites

Feeds into