Quiz: RANSAC
Before this unit: The generalised Hough transform (previous unit); Day 2: Edges, blobs and ridges.
See also: Day 12: Thresholding; Day 9: Radon transform and tomography.
Short questions to test your understanding. Try each on paper first, then open the answer. w is the inlier fraction, s the sample size, N the number of samples, \varepsilon the inlier distance.
Q1. Why does a least-squares line fit fail when 30 % of the points are outliers?
How much does one point 30 px from the line cost?
Least squares minimises the sum of squared distances. A point 30 px away costs 900, as much as 900 points 1 px away, so a few far outliers dominate the sum and pull the line towards them. Every point has a say, including the ones that do not belong to the line.
Q2. Why does RANSAC fit its sample with the smallest possible number of points (2 for a line)?
What must be true of the sample for the guess to be good?
A guess is only good if every point in the sample is an inlier. The probability of that is w^s, which falls quickly with s: with w = 0.5, 0.25 for 2 points, 0.125 for 3, 0.03 for 5. The smallest sample that determines the model maximises the chance of a clean sample.
Q3. How many samples are needed for a 99 % chance of at least one all-inlier sample, for a line with half the points inliers? And for a circle?
N = \log(1 - p)/\log(1 - w^s), rounded up.
Line: \log 0.01/\log 0.75 = 16.0, so 17. Circle (s = 3): \log 0.01/\log 0.875 = 34.5, so 35. The number of points does not enter.
Q4. Why is the best model refitted by least squares at the end, and why only on its inliers?
How many points determined the best model?
The best model passes exactly through its 2 (or 3) sample points, which are noisy, so it is only roughly right. Least squares on all its inliers averages their noise and gives a more precise model. Only the inliers, because including the outliers would bring back the very problem RANSAC solves.
Q5. Two parallel lines lie 8 px apart, and \varepsilon is set to 6 px. What does RANSAC find?
How wide is the band of a model halfway between the lines?
A line between the two: its band of ±6 px contains both lines (each 4 px from it), so it has more inliers than either true line and wins. \varepsilon must be smaller than half the distance between models you want to keep apart, but larger than the noise of the inliers.
Q6. The inlier fraction drops from 0.5 to 0.2. By what factor does the required number of samples grow for a line? Why is the Hough transform not hurt in the same way?
For small w^s, N \approx 4.6/w^s.
From 17 to 113, about 6.6 times; for small w, N \approx 4.6/w^2, so roughly (0.5/0.2)^2 = 6.25. The Hough transform lets every point vote once per angle, whatever the fraction of outliers: the true line still collects its votes in one bin, while the outliers’ votes spread over many bins. As long as the peak stands above the floor, it is found, with a fixed amount of work.
Q7. Which method would you use to fit an affine transform (6 parameters) to 200 matched point pairs of which 40 % are wrong, and why?
How large is a 6D accumulator? How many samples does RANSAC need?
RANSAC. An affine transform is determined by 3 point pairs, so s = 3, w = 0.6: N = \log 0.01/\log(1 - 0.216) = 19 samples for 99 %. A Hough accumulator with only 20 steps per parameter would have 20^6 = 64 million cells.
Q8. (math) Show that the total-least-squares line through a set of points passes through their centroid and has as its normal the eigenvector of the scatter matrix with the smaller eigenvalue.
Minimise \sum_i (\mathbf n^\top \mathbf p_i - \rho)^2 first over \rho, then over unit \mathbf n.
The derivative with respect to \rho is -2\sum_i(\mathbf n^\top\mathbf p_i - \rho) = 0, so \rho = \mathbf n^\top\bar{\mathbf p}: the centroid is on the line. Substituting, the cost is \sum_i (\mathbf n^\top(\mathbf p_i - \bar{\mathbf p}))^2 = \mathbf n^\top S\,\mathbf n with S = \sum_i(\mathbf p_i - \bar{\mathbf p})(\mathbf p_i - \bar{\mathbf p})^\top. For unit \mathbf n this Rayleigh quotient is smallest at the eigenvector of the smallest eigenvalue: the normal points in the direction of least spread, and the line along the direction of largest spread (the first principal component).