Sample, fit, score
RANSAC repeats three steps times:- Draw a minimal sample of data points at random.
- Fit the model to those points exactly. For a line, points determine .
- Score the fit on all the data. The basic score is the size of the consensus set, the number of points whose residual satisfies for a threshold .
How many trials
When all of its points are inliers, a minimal sample consists only of inliers. If the points are drawn independently and the inlier fraction is , this happens with probability . The probability that a trial fails to draw an all-inlier sample is , and the probability that all independent trials fail is . Requiring at least one all-inlier sample with probability means , so is a confidence you choose, often 0.99 or 0.999, and every quoted number of trials depends on it. Drawing without replacement makes the true probability of an all-inlier sample slightly smaller than ; for much larger than the difference is negligible.The threshold as a chi-squared gate
The threshold should accept a known fraction of the inliers. Under the inlier model the residual is Gaussian, , so follows a distribution with one degree of freedom. When the residual is a vector of dimension with independent components of variance , such as the 2D reprojection error of a homography, follows . To accept an inlier with probability , set where is the quantile. The threshold then follows from the same noise model as the least squares fit. A larger accepts more inliers and also lets more outliers fall inside the band.Scoring: MSAC and MLESAC
Counting inliers treats every point inside the band alike and every point outside alike. Two refinements by Torr and Zisserman (2000) score hypotheses more finely. MSAC charges each point its squared residual, capped at : Among hypotheses with the same consensus set it prefers the one that fits the inliers better. MLESAC goes further and scores each hypothesis by the likelihood of the inlier and outlier mixture of the EM section, with known and estimated for each hypothesis by a few EM steps on alone: compute the responsibilities , set to their mean, repeat. Counting inliers is the hard version of this: the test replaces the responsibility by 0 or 1, as the k-means indicator replaces the responsibilities of a Gaussian mixture. The experiment below compares the three scores on 300 data sets with the same line, 60 points and half of them uniform outliers. Each run uses 30 trials, and the code records the slope error of the best hypothesis before any refit.Refinement
The winning hypothesis was fitted to only points, so its accuracy is that of noisy measurements. The final step refits the model to the whole consensus set by least squares, which uses all the inliers. Because the refit line can change which points fall inside the band, the refit and the inlier test can be repeated until the consensus set stops changing. Starting EM on the inlier and outlier mixture from the RANSAC fit goes one step further, and replaces the hard consensus set by responsibilities. It gives EM the uncontaminated start that the grid example of the previous section lacked.Where RANSAC stops working
The grid model of the previous section has 82 columns. A minimal sample would be hours, and the probability that 82 random hours are all inliers is . The code compares the number of trials with that of a line, at .References
- Hartley, R., Zisserman, A. (2004). Multiple View Geometry in Computer Vision.
- (n.d.). Foundations of Computer Vision.
- Bishop (n.d.). Pattern Recognition and Machine Learning.
Found an error on this page? Report an issue.

