Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Kornia Kornia Inlier Mask Indexing

From Leeroopedia


Knowledge Sources
Domains Vision, Geometry
Last Updated 2026-02-09 15:00 GMT

Overview

Pattern for extracting verified correspondences using PyTorch boolean tensor indexing on RANSAC inlier masks.

Description

This is a user-defined pattern, not a library API. After RANSAC returns an inlier mask (boolean tensor), correspondences are filtered via standard PyTorch boolean indexing: kp1_verified = kp1[inlier_mask], kp2_verified = kp2[inlier_mask]. The pattern is simple but foundational for extracting clean correspondences for downstream geometric computation.

Usage

Apply immediately after RANSAC to separate inlier from outlier correspondences.

Code Reference

Source Location

  • Repository: kornia
  • File: kornia/geometry/ransac.py (forward returns inlier mask)
  • Lines: L335-400

Interface Pattern

kp1_verified = kp1[inlier_mask]
kp2_verified = kp2[inlier_mask]

Import

N/A (uses PyTorch tensor indexing)

I/O Contract

Inputs

Name Type Required Description
kp1 torch.Tensor Yes Original keypoints from image 1 of shape (N, 2)
kp2 torch.Tensor Yes Original keypoints from image 2 of shape (N, 2)
inlier_mask torch.Tensor Yes Boolean mask of shape (N,) from RANSAC

Outputs

Name Type Description
kp1_verified torch.Tensor (M, 2) Verified keypoints from image 1, where M = sum(inlier_mask)
kp2_verified torch.Tensor (M, 2) Verified keypoints from image 2, where M = sum(inlier_mask)

Usage Examples

Basic Inlier Extraction

import torch
from kornia.geometry import RANSAC

ransac = RANSAC(model_type="homography", inl_th=2.0)
kp1 = torch.rand(200, 2) * 256
kp2 = torch.rand(200, 2) * 256

homography, inlier_mask = ransac(kp1, kp2)

# Extract inlier correspondences
kp1_verified = kp1[inlier_mask]
kp2_verified = kp2[inlier_mask]
print(f"Verified matches: {kp1_verified.shape[0]}")

Computing Inlier Ratio

import torch
from kornia.geometry import RANSAC

ransac = RANSAC(model_type="fundamental", inl_th=1.0)
kp1 = torch.rand(300, 2) * 480
kp2 = torch.rand(300, 2) * 480

model, inlier_mask = ransac(kp1, kp2)

inlier_ratio = inlier_mask.sum().item() / len(inlier_mask)
print(f"Inlier ratio: {inlier_ratio:.2%}")

if inlier_ratio > 0.3:
    kp1_clean = kp1[inlier_mask]
    kp2_clean = kp2[inlier_mask]

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment