Random Sample Consensus (RANSAC) algorithm Introduction

Source: Internet
Author: User

Blink of an eye 2012 years after three months, recently in the target tracking, need to use the RANSAC algorithm for image matching, using Opencv+vs to achieve. Finally the initial results ah, very excited and very excited, here mark, for future use! Here does not stick the source code, thinks all is the tear!

The RANSAC is the abbreviation for "Random sample Consensus (consistent randomly sampled)". It allows you to iteratively estimate the parameters of a mathematical model from a set of observational datasets that contain "outliers". It is an indeterminate algorithm-it has a certain probability to get a reasonable result, and the number of iterations must be increased in order to improve the probability. The algorithm was first proposed by Fischler and Bolles in 1981.

the basic assumptions of RANSAC are:
(1) The data is composed of "insider points", for example: the distribution of data can be explained by some model parameters;
(2) "Outliers" are data that cannot be adapted to the model;
(3) The data in addition is noise.
The reasons for the outliers are: The extreme value of the noise, the method of measuring the error, and the false hypothesis of the data.

Ransac also makes the assumption that given a set of (usually very small) insider points, there is a process for estimating model parameters that can be interpreted or applied to an insider point.

One, example
A simple example is to find the right 2-dimensional straight line from a set of observational data. It is assumed that the observed data contains an inside point and an outer point, in which the inter-point approximation is passed by a straight line, and the outliers are far away from the line. The simple least squares method cannot find a straight line that adapts to the internal point, because the least squares method tries to accommodate all points including outliers. Instead, RANSAC can conclude that a model is calculated using only an insider's point, and that the probability is high enough. However, RANSAC does not guarantee that the results must be correct, in order to ensure that the algorithm has a reasonable probability of high enough, we must carefully select the parameters of the algorithm.

Left: Datasets with many outliers right: Ransac found lines (outliers do not affect results)


Ii. Overview
The input of the RANSAC algorithm is a set of observational data, a parametric model that can be interpreted or adapted to observational data, and some credible parameters.
Ransac the goal by repeatedly selecting a set of random subsets in the data. The selected subset is assumed to be an insider, and is validated using the following method:
1. There is a model adapted to the hypothetical insider point, where all the unknown parameters can be calculated from the hypothetical insider points.
2. Use the model obtained in 1 to test all other data, if a point applies to the estimated model, it is considered an insider point.
3. If there are enough points to be classified as hypothetical insider points, then the estimated model is reasonable enough.
4. The model is then re-evaluated with all the hypothetical insider points, as it is only estimated by the initial assumption-points.
5. Finally, the model is evaluated by estimating the error rate of the insider and the model.
This process is repeated for a fixed number of times, and each time the resulting model is either discarded because it is too small, or is chosen better than the existing model.


third, the algorithm
The pseudo-code form of the algorithm is as follows:
Input:
data--a set of observational data
model--models adapted to the data
n--minimum number of data for a model
Number of iterations of the k--algorithm
t--is used to determine whether the data fits into the model's thresholds
d--determining whether a model is suitable for data sets
Output:
best_model--the model parameter that best matches the data (returns NULL if no good model is found)
best_consensus_set--estimating the data points of the model
best_error--estimated model errors related to data

Iterations = 0
Best_model = null
Best_consensus_set = null
Best_error = Infinity
while (Iterations < k)
Maybe_inliers = Random selection of n points from the data set
Maybe_model = Model parameters suitable for maybe_inliers
Consensus_set = Maybe_inliers

For (points that do not belong to maybe_inliers in each data set)
if (if the point is appropriate for Maybe_model and the error is less than T)
Add a point to the Consensus_set
if (the number of elements in Consensus_set is greater than D)
Have found a good model, now test how good the model is
Better_model = Suitable for some model parameters in Consensus_set
This_error = Better_model exactly how to fit the measurements of these points
if (This_error < Best_error)
We found a better model than before, and saved the model until the best model appeared
Best_model = Better_model
Best_consensus_set = Consensus_set
Best_error = This_error
Increase the number of iterations
Back to Best_model, Best_consensus_set, Best_error

Some of the possible changes to the RANSAC algorithm include the following:
(1) If a good enough model is found (the model has a small enough error rate), jump out of the main loop. This may save time to calculate additional parameters.
(2) Calculate the This_error directly from the Maybe_model, without re-estimating the model from Consensus_set. This may save time comparing two model errors, but may be more sensitive to noise.

Iv. Parameters
We had to determine the parameters T and D based on the specific problem and data set through the experiment. However, the parameter K (iteration count) can be inferred from theoretical results. When we estimate the model parameters, we use p to denote the probability that the points randomly selected from the data set during the iterative process are the internal points, so the result model is likely to be useful, so p also characterizes the probability that the algorithm produces useful results. Use W to indicate the probability of selecting an insider point from the dataset each time, as shown in the following form:
w = number of insider points/number of datasets
Normally, we don't know the value of W in advance, but we can give some robust values. Assuming that the estimated model requires the selection of n points, Wn is the probability that all n points are in-between points;1? W N is the probability that at least one point in N points is an outlier, which indicates that we have estimated a bad model from the data set.(1?) W n) k The representation algorithm never chooses the probability that N points are an insider, and it is the same as 1-p. So
1? p = (1?) W n) k
We take the logarithm on both sides of the upper formula and draw

It is worth noting that the result assumes that n points are selected independently, that is, when a point is selected, it may be repeatedly selected by subsequent iterations. This method is often unreasonable, and the resulting k value is considered to be the upper bound of the selected non-repeating point. For example, to find a suitable line from a dataset, the RANSAC algorithm typically selects 2 points per iteration, and calculates a straight maybe_model through these two points, requiring that the two points must be unique.
In order to obtain more credible parameters, the standard deviation or its product can be added to K. The standard deviation of k is defined as:

v. Advantages and Disadvantages
The advantage of RANSAC is that it can be robust in estimating model parameters. For example, it can estimate high-precision parameters from a dataset that contains a large number of outliers. The disadvantage of RANSAC is that it calculates the number of iterations with no upper limit, and if the maximum number of iterations is set, the resulting results may not be optimal and may even result in incorrect results. Ransac only a certain probability to obtain a credible model, the probability is proportional to the number of iterations. Another disadvantage of RANSAC is that it requires setting thresholds related to the problem.
RANSAC can only estimate a model from a specific data set, and if there are two (or more) models, RANSAC cannot find another model.

Vi.. Application
RANSAC algorithms are often used in computer vision, for example, to simultaneously solve related problems and estimate the basic matrix of stereoscopic cameras.

personal sentiment: from the blunt formula to the living execution effect, or more twists and turns, which did experience a lot of hardships. But in their own efforts, one by one to conquer. Although a lot of detours, but the outcome is not too bad. The algorithm is like this, you to it ruthless point, it will smile to you, haha, continue to struggle!     

March 25, 2012 in Chengdu

Random Sample Consensus (RANSAC) algorithm Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.