Expand description
RANSAC robust model fitting (lines and planes).
RANSAC (RANdom SAmple Consensus) is an iterative method for estimating the parameters of a mathematical model from a set of observed data that contains a large fraction of outliers. This module provides robust fitting of:
- 2D lines (
a x + b y + c = 0, normalizeda² + b² = 1) viaransac_fit_line. - 3D planes (
a x + b y + c z + d = 0, normalizeda² + b² + c² = 1) viaransac_fit_plane.
The implementation follows the classic Fischler–Bolles algorithm with an adaptive stopping criterion: the required number of iterations is recomputed whenever a better consensus set is found, so clean data terminates quickly while noisy data exhausts the iteration budget.
§Robustness details
The fit complements Slice 21’s Weiszfeld geometric_median: where the
geometric median is robust to outliers in a location estimate, RANSAC is
robust to outliers in a parametric model estimate. After the consensus set
is found, the model is refined with total (orthogonal) least squares on the
inliers, which minimizes the perpendicular distances rather than the
vertical residuals — appropriate when there is no privileged axis.
§Determinism
No external RNG is used. Sampling relies on a deterministic Knuth MMIX linear
congruential generator seeded by RansacOptions::seed, so identical inputs
and seeds always produce identical results (see the seed-reproducibility
tests). This honors the project’s SciRS2 policy (no rand / rand_distr).
§Example
use oxigdal_algorithms::vector::{Point, RansacOptions, ransac_fit_line};
// Points on the line y = 2x + 1 with one gross outlier.
let points = [
Point::new(0.0, 1.0),
Point::new(1.0, 3.0),
Point::new(2.0, 5.0),
Point::new(3.0, 7.0),
Point::new(4.0, 9.0),
Point::new(2.0, 50.0), // outlier
];
let result = ransac_fit_line(&points, &RansacOptions::default())?;
assert!(result.converged);
assert!(!result.inliers.contains(&5)); // outlier rejectedStructs§
- Ransac
Line Model - A 2D line in implicit form
a x + b y + c = 0with the normal(a, b)normalized so thata² + b² = 1. - Ransac
Options - Configuration for RANSAC fitting.
- Ransac
Plane Model - A 3D plane in implicit form
a x + b y + c z + d = 0with the normal(a, b, c)normalized so thata² + b² + c² = 1. - Ransac
Result - Result of a RANSAC fit.
Functions§
- ransac_
fit_ line - Robustly fits a 2D line to
pointsusing RANSAC. - ransac_
fit_ plane - Robustly fits a 3D plane to
pointsusing RANSAC.