estimated model is reasonably good if sufficiently many data points have been classified as a part of the consensus set. The model may be improved by re-estimating it by using all the members of the consensus set. The fitting quality as a measure of how well the model fits to the consensus set will be used to sharpen the model fitting as iterations goes on (e.g., by setting this measure as the fitting quality criteria at the next iteration). To converge to a sufficiently good model parameter set, this procedure is repeated a fixed number of times, each time producing either the rejection of a model because too few points are a part of the consensus set, or a refined model with a consensus set size larger than the previous consensus set. Pseudocode The generic RANSAC algorithm works as the following pseudocode: Given: data – A set of observations. model – A model to explain the observed data points. n – The minimum number of data points required to estimate the model parameters. k – The maximum number of iterations allowed in the algorithm. t – A threshold value to determine data points that are fit well by the model (inlier). d – The number of close data points (inliers) required to assert that the model fits well to the data. Return: bestFit – The model parameters which may best fit the data (or null if no good model is found). iterations = 0 bestFit = null bestErr = something really large // This parameter is used to sharpen the model parameters to the best data fitting as iterations goes on. while iterations < k do maybeInliers := n randomly selected values from data maybeModel := model parameters fitted to maybeInliers confirmedInliers := empty set for every point in data do if point fits maybeModel with an error smaller than t then add point to confirmedInliers end if end for if the number of elements in confirmedInliers is > d then // This implies that we may have found a good model. // Now test how good it is. betterModel := model parameters fitted to all the points in confirmedInliers thisErr := a measure of how well betterModel fits these points if thisErr < bestErr then bestFit := betterModel bestErr := thisErr end if end if increment iterations end while return bestFit Example code A Python implementation mirroring the pseudocode.