This is the tutorial for the RANSAC algorithm taught at the Technische Hochschule Ingolstadt, in the course of mobile robotics. The script generate_data.m provides a data set, containing a circle and a line pattern, including additional noise.
The principle of the RANSAC is summarized by the following steps:
- Select a random subset of the original data. Call this subset the hypothetical inliers.
- A model is fitted to the set of potential inliers
- The complete data is then tested against the fitted model. Those points that fit the estimated model well, according to some model-specific loss function, are considered as part of the consensus set.
- The estimated model is reasonably good if sufficiently many points have been classified as part of the consensus set.
- Afterwards, the model may be improved by reestimating it using all members of the consensus set, by applying the least square approach.
Use the existing template to write the RANSAC algorithm to find the line.
Use the highlighted placeholders to add your code to complete the algorithm.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ADD YOUR CODE HERE %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Have a close look in the code and its comments, which provide extra help for the implementation.
Two points are necessary to calculate the model for a randomly selected set of points. You can use the known equation, but there is a much simpler solution to this.
Your solution should lead to a similar result like the following figure.
If you finished the first task, extend your approach, so the circle is found.
The equation for a circle is described by the error term in the least square approach via:
Based on partial derivative the error term can be solved. The result are the following equations,
which form a linear equation system; here presented as matrices.
Finally, the circles radius can be calculated where
The solution of the RANSAC for the circle should look similar to the following figure.