RANSAC
Random Sample Consensus. An iterative algorithm for robustly estimating model parameters from data containing outliers. Essential for homography estimation and 3D point cloud fitting in computer vision.
RANSAC (Random Sample Consensus), proposed by Fischler and Bolles in 1981, is a robust estimation algorithm designed to fit models to data contaminated with a significant proportion of outliers. Unlike least-squares methods that treat all data points equally and are easily corrupted by outliers, RANSAC iteratively identifies the largest subset of data consistent with a hypothesized model.
The algorithm follows a straightforward procedure: randomly select the minimum number of points required to define the model, compute the model parameters from this minimal set, then count how many remaining data points (inliers) fall within a distance threshold of the model. This process repeats for a predetermined number of iterations, and the model with the most inliers is selected as the final result.
- Iteration count: The required number of iterations is computed as
k = log(1-p) / log(1-w^n), where w is the inlier ratio, n is the minimum sample size, and p is the desired success probability. For a homography (n=4) with 50% inliers and 99% confidence, approximately 72 iterations are needed - Threshold selection: The inlier distance threshold depends on measurement noise. Values of 1-3 pixels are typical for image correspondences. Too small a threshold rejects valid inliers; too large admits outliers
- Variants: MSAC scores inliers by their distance rather than binary classification. PROSAC samples correspondences in quality order for faster convergence. LO-RANSAC applies local optimization to promising hypotheses
In computer vision, RANSAC is the standard method for estimating homographies and fundamental matrices after feature matching. OpenCV's cv2.findHomography() internally runs RANSAC and returns both the transformation matrix and an outlier mask, enabling downstream processing to use only geometrically consistent correspondences.