Let Probability of inliers = $w$ = $\frac{\text{Number of inliers}}{\text{Total number of points}}$
Probability that the $k$ points in the minimal set are all inliers = $w^k$
Probability that atleast one of the $k$ point is outlier = $1 - w^k$
Probability atleast one of the $k$ point is outlier in n iterations = $(1 - w^k)*n$
If p is the probability that after $n$ iteration we finds an inlier. Then there is $1 - p$ probability that after $n$ iterations, we don't have atleast one of the $k$ points as outlier in $n$ iterations.
So, we get --
\begin{align} 1 - p &= (1 - w^k)*n \\ log(1 - p) &= n log(1 - w^k) \\ n &= \frac{log(1 - p)}{log(1 - w^k)} \\ \end{align}%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
def iters_needed(k, p=.99, w = .5):
"""
Returns the number of ransac iterations needed.
:param k : Minimal set of points.
:param w : Percentage of inliers.
:param p : Desired Accuracy
"""
return np.log(1-p)/np.log(1 - np.power(w, k))
x = range(1, 10)
y = [iters_needed(x_i) for x_i in x]
plt.plot(x, y)
plt.title('Number of iterations VS Minimal set of inliers')
plt.xlabel('Number of iterations')
plt.ylabel('Minimal set of inliers')
plt.show()