PIXELBANKv9.1.0
Menu

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:

  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:
  1. Calculate Inlier Ratio: ε = 1 - 0.3 = 0.7
  2. Calculate P_clean: P_clean = 0.7^4 = 0.2401
  3. Calculate K: K = log(1 - 0.99) / log(1 - 0.2401) = log(0.01) / log(0.7599) ≈ 16.8
  4. Ceiling: K = 17

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)
solution.py

Test Results

0/0
Run code to see test results.
Feature Correspondence Filtering using RANSAC - Medium | PixelBank