v9.1.1
Menu

Feature Correspondence Filtering using RANSAC

mediumFREEGraphsGeometry, Robust EstimationCV - DSA

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:

  1. Selects a minimal random subset of correspondences (e.g., 4 points for a Homography)
  2. Computes the transformation parameters based only on this minimal subset
  3. 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 pp.

Formulas

The probability PcleanP_{clean} of randomly choosing a minimal subset (size MM) consisting entirely of inliers (assuming inlier ratio ε\varepsilon) is:

Pclean=εMP_{clean} = \varepsilon^M

The required number of iterations KK to ensure at least one clean sample with probability pp is:

K=log⁡(1−p)log⁡(1−Pclean)K = \frac{\log(1 - p)}{\log(1 - P_{clean})}

Calculate KK given the inputs and return it as an integer (ceiling the result).

Example

Input
M=4, R_outlier=0.3, p=0.99
Output
17
Reasoning
  • Inputs: M =4= 4 is the minimal subset size (four correspondences, enough for a homography), R_outlier =0.3= 0.3 says 30% of the matches are wrong, and p =0.99= 0.99 is the confidence that at least one draw is all inliers.
  • Inlier ratio: ε=1−0.3=0.7\varepsilon = 1 - 0.3 = 0.7, so any single match is good with probability 0.70.7.
  • Clean subset: all four picks must be inliers, so Pclean=0.74=0.2401P_{clean} = 0.7^4 = 0.2401. Each draw fails with probability 1−0.2401=0.75991 - 0.2401 = 0.7599.
  • Iterations: KK draws all fail with probability 0.7599K0.7599^K, and we need that to be at most 1−p=0.011 - p = 0.01. Solving gives K=ln⁡0.01ln⁡0.7599=−4.6052−0.2746≈16.77K = \frac{\ln 0.01}{\ln 0.7599} = \frac{-4.6052}{-0.2746} \approx 16.77.
  • Output: a fractional draw is impossible, so 16.7716.77 is rounded up to 17. Check: 0.759916≈0.01240.7599^{16} \approx 0.0124 is still above 0.010.01, while 0.759917≈0.00940.7599^{17} \approx 0.0094 is below it.
  • Notice how fast this grows: with M=8M = 8, half the matches wrong and p=0.95p = 0.95, Pclean=0.58≈0.0039P_{clean} = 0.5^8 \approx 0.0039 and KK jumps to 766766.

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)

Learn this in

More from CV - DSA

solution.py

Test results

Sign in to run your code against the test cases.