2.1.1 Leveling Algorithm
The developed leveling algorithm expands upon the
idea of line-by-line leveling by introducing a new
way of automatically excluding objects through the
use of RANSAC (Random Sample Consensus) (Fis-
chler and Bolles, 1980). RANSAC is suitable as it
is able to estimate parameters of a given model (in
this case a 1st or 2nd order polynomial) from a data
set (a line from the image) contaminated with outliers
(objects). RANSAC basically works by repeatedly
making guesses at a solution based on n randomly se-
lected initial points, where n is the minimum number
of points required to determine the parameters of the
model. Each solution is then evaluated and compared
against the current best guess, yielding the best guess
as the solution in the end.
RANSAC is therefore non-deterministic and its
success depends on the number of iterations k which
RANSAC is allowed to execute. k can be determined
theoretically based on two assumptions:
The solution is considered decent if:
• All the n initial points are inliers, i.e. part of the
polynomial to be removed.
• The n initial points are not closely grouped to-
gether, which is evident be contemplating e.g. 2nd
order polynomials.
For the sake of simplicity, the number of data points
is divided into n evenly sized intervals and the n
initial points are considered to be appropriately
spaced if each resides in an interval of its own.
Hence, the probability of never reaching a de-
cent solution out of k iterations is given by:
P(bad) = (1 − P(in)
n
× P(spaced))
k
(1)
where P(in) is the probability of a point being an
inlier and P(spaced) is the probability of the n
points being appropriately spaced, i.e. P(spaced) =
(1/n)
n
. The probability of reaching a decent solution
P(decent) out of k iterations must then be given by:
1 − P(decent) = (1 − P(in)
n
× (1/n)
n
)
k
(2)
from where k can be isolated:
k =
log(1 − P(decent))
log(1 − P(in)
n
× (1/n)
n
)
(3)
Considering a scenario with 50% outliers, i.e. P(in) =
0.50, and it would take:
k =
log(1 − 0.999)
log(1 − 0.50
3
× (1/3)
3
)
≈ 1488 (4)
iterations to find a decent solution with a probability
of P(decent) = 99.9% when using n = 3 initial
points, which is sufficient for a 2nd order polynomial.
Another solution could be to divide each line
into n evenly sized intervals and then randomly
choose one point from each interval as the n initial
point. This would reduce the number of iterations k
to:
k =
log(1 − P(decent))
log(1 − P(in)
n
)
(5)
as it is no longer necessary to check the spacing be-
tween the points, i.e. take P(spaced) into account.
However, this method was found to be inconsis-
tent during tests on real data, as it would repeat-
edly fail at images with un-evenly distributed outliers,
where the majority of outliers would reside in one of
the fixed intervals. The idea of using fixed intervals
was therefore discarded.
2.1.2 Performance Considerations
A runtime test of a generic RANSAC algorithm is
performed to determine whether the k = 1488 from
Equation 4 is realistic. The algorithm is implemented
in C++ and is performed on a laptop with a P8600
@ 2.4GHz CPU. On average (100 repetitions) it
took 0.88 seconds to execute the algorithm. Hence,
it would take 3 minutes and 45 seconds to apply
RANSAC on each horizontal line in a relatively small
image of 256 × 256 pixels, which is not acceptable.
In order to reduce runtime, RANSAC is only
used to exclude objects in the first line of the image.
In the following lines, the exclusion of objects is
achieved by ignoring every point x in the line l(x)
which is not within a fixed threshold t from the
polynomial p(x)
latest
found in the previous line. I.e.
only points which fulfils
t
2
> (p(x)
latest
− l(x))
2
(6)
are used when fitting the polynomial to be subtracted
in every line, apart from the first line where RANSAC
is used.
2.1.3 Final Leveling Algorithm
The final leveling algorithm is as follows:
1. Fit a polynomial p(x)
latest
to the first line l
1
in the
AFM image using RANSAC.
2. Find inliers in the next line based on p(x)
latest
and
a fixed threshold t.
3. Fit a polynomial to the found inliers and subtract
the found polynomial from the current line.
VISAPP 2016 - International Conference on Computer Vision Theory and Applications
114