Feature Correspondence Filtering using RANSAC
Problem Statement
When matching visual features (like SIFT keypoints) between two images, the resulting list of correspondences often contains outliers due to misidentifications or repetitive patterns. To robustly estimate the geometric transformation (like a homography or affine map) relating the two images, the Random Sample Consensus (RANSAC) algorithm is employed.
RANSAC Algorithm
RANSAC repeatedly:
- Selects a minimal random subset of correspondences (e.g., 4 points for a Homography)
- Computes the transformation parameters based only on this minimal subset
- Tests all other correspondences against the computed model to count inliers
Your Task
Calculate the probability of selecting a "clean" minimal subset given a known outlier ratio and determine the minimum number of RANSAC iterations required to achieve a specified success probability .
Formulas
The probability of randomly choosing a minimal subset (size ) consisting entirely of inliers (assuming inlier ratio ) is:
The required number of iterations to ensure at least one clean sample with probability is:
Calculate given the inputs and return it as an integer (ceiling the result).
Example
M=4, R_outlier=0.3, p=0.99
17
- Inputs:
Mis the minimal subset size (four correspondences, enough for a homography),R_outliersays 30% of the matches are wrong, andpis the confidence that at least one draw is all inliers. - Inlier ratio: , so any single match is good with probability .
- Clean subset: all four picks must be inliers, so . Each draw fails with probability .
- Iterations: draws all fail with probability , and we need that to be at most . Solving gives .
- Output: a fractional draw is impossible, so is rounded up to
17. Check: is still above , while is below it. - Notice how fast this grows: with , half the matches wrong and , and jumps to .
Constraints
- M (minimal subset size) is an integer ≥ 2
- R_outlier (outlier ratio) is a float between 0 and 1
- p (desired success probability) is a float between 0 and 1
- Output K must be an integer (ceiling the result of the log calculation)