Goal
Robustly fit a parametric model (homography, fundamental matrix, or essential matrix) to a set of data points contaminated by outliers, without a user-tuned inlier threshold . Inputs: data set ; minimal sample size ; residual function ; upper noise-scale bound (replaces the hard threshold ); confidence target . Outputs: weighted-least-squares model and marginalised quality score . The defining property is -consensus: the noise scale is treated as a random variable uniformly distributed on , and the RANSAC quality function is marginalised over (Eq. 2); the final model is a weighted least-squares fit using the marginalised inlier likelihoods as IRLS weights (Alg. 1), with no hard inlier/outlier partition.
Algorithm
Let denote the set of data points and the point count. Let denote the minimal sample size required to instantiate the model. Let denote the noise scale and its upper bound. Let denote the residual of point under model . Let denote the chi-squared inlier-residual density with degrees of freedom — a function of radius and scale . Let denote the effective inlier threshold at noise scale . Let denote the marginalised inlier likelihood of point under model , used as the IRLS weight. Let denote the marginalised quality score. Let denote the number of uniform partitions of used for discretisation (default ). Let denote the confidence target for the stopping criterion. Let denote the SPRT pre-screen reference threshold (set to 1 pixel).
The RANSAC quality function averaged over uniformly distributed on :
The 0.95 quantile of . For inlier residuals (2D point correspondences):
The marginalised inlier likelihood — used as the IRLS weight in the final weighted least-squares refit:
Computed on a grid of uniform partitions of .
Procedure
- Sample. Draw a minimal sample of size from (uniform or PROSAC-ordered).
- Fit minimal model. Instantiate from the sample.
- Compute marginalised quality. Discretise over uniform partitions of and approximate via the discretised form (Eq. 5).
- SPRT pre-screen with reference threshold pixel — cheap rejection of obviously bad models, reused from USAC.
- If exceeds the running maximum, refine via IRLS. Compute weights for every point. Refit by weighted least squares. Iterate until convergence.
- Update best model and termination criterion. The termination count is also marginalised over (Eq. 8) and updated each time a new best model is found. Repeat from step 1 until confidence is reached.
Implementation
MAGSAC -consensus quality computation in Rust:
/// Discretised σ-consensus quality (MAGSAC).
/// Returns (Q*, per-point weights) for use in IRLS refit.
pub fn magsac_quality<F>(
residuals: &[f64],
sigma_max: f64,
d: usize,
g: F, // chi-squared density g(r | σ)
) -> (f64, Vec<f64>)
where F: Fn(f64, f64) -> f64
{
let dsigma = sigma_max / d as f64;
let mut weights = vec![0.0_f64; residuals.len()];
let mut q_star = 0.0;
for i in 1..=d {
let sigma = i as f64 * dsigma;
let tau = 3.64 * sigma; // χ²(4), 0.95 quantile
for (j, &r) in residuals.iter().enumerate() {
let w = if r <= tau { g(r, sigma) } else { 0.0 };
weights[j] += w * dsigma;
q_star += w * dsigma;
}
}
// Normalise by σ_max (uniform prior on σ).
let inv = 1.0 / sigma_max;
for w in weights.iter_mut() { *w *= inv; }
(q_star * inv, weights)
}
Remarks
- -consensus eliminates the user-tuned inlier threshold — replacing it with the upper bound (10 pixels across all experiments), which is much less sensitive to precise tuning than a hard threshold.
- Discretisation grid reduces fitting cost from to per hypothesis. Values below risk underweighting high- components; the paper provides no sensitivity sweep beyond the empirical choice.
- Per-point weights are marginalised inlier likelihoods. The final model is a weighted-least-squares fit via IRLS, not a hard inlier-set refit.
- For residuals (2D point correspondences), the effective inlier threshold at each is . For higher residual dimensions the constant changes; consult the appropriate quantile table.
- Float32 underflow safety: underflows in float32 when px for px — safely beyond the gate, so float32 arithmetic is workable throughout the loop.
- See
raguram-usacfor the unifying RANSAC engineering framework MAGSAC plugs into, including the When to choose USAC over MAGSAC discussion (hosted there per the older + broader-scope tiebreaker). Seeransacfor the four design axes that organise the modern RANSAC family.
References
- D. Barath, J. Matas, J. Noskova. MAGSAC: Marginalizing Sample Consensus. Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2019. arxiv.org