RANSAC Iteration Count
You are given the estimated inlier ratio and need to calculate how many RANSAC iterations are required for a given success probability.
The formula for required iterations is:
Where:
- = number of iterations needed
- = desired probability of success (e.g., 0.99)
- = inlier ratio (proportion of good correspondences)
- = sample size (points needed for model, e.g., 4 for homography)
This formula comes from the probability that at least one sample contains all inliers after k iterations.
Example
inlier_ratio = 0.5 sample_size = 4 success_prob = 0.99
72
- Probability of all-inlier sample: w^n = 0.5^4 = 0.0625
- Probability of at least one outlier: 1 - w^n = 0.9375
- Probability of k failures: (1 - w^n)^k
- For 99% success: 1 - (1 - w^n)^k >= 0.99 → (1 - w^n)^k <= 0.01 → k * log(1 - w^n) <= log(0.01) → k >= log(0.01) / log(0.9375) → k >= log(1 - 0.99) / log(1 - 0.0625) → k >= -4.605 / -0.0645 ≈ 71.35
Ceiling: k = 72 iterations needed
Constraints
- inlier_ratio: proportion of inliers (0 < w < 1)
- sample_size: number of points per sample (positive integer)
- success_prob: desired probability of finding good model (default 0.99)
- Return number of iterations (ceiling of computed value)
- Handle edge cases: w=1 returns 1, w=0 returns infinity