Overview

pyransac is a general-purpose random sample consensus (RANSAC) framework written in Python. You can use it to remove outliers from your data sets given a data model to which you expect your data to fit. For convenience, some data models (such as a 2D straight line) are already provided. However, you are free to define your own data models.

Installation

You can install pyransac using pip with the following command:

$ python3 -m pip install pyransac

Getting Started

After installing pyransac, all you need to do is create a data model definition (or use one of the built in models) and specify the RANSAC algorithm parameters. From there you can call the find_inliers function and pass in your data, model, and parameters. The function will return a list of your inliers.

Example Program

The following is a simple example of filtering data against a 2D line model.

 1import pyransac
 2from pyransac import line2d
 3
 4# Create data
 5inliers = [line2d.Point2D(x, x) for x in range(0, 10)]
 6outliers = [line2d.Point2D(x ** 2, x + 10) for x in range(0, 5)]
 7data = inliers + outliers
 8
 9# Specify our RANSAC parameters
10params = pyransac.RansacParams(samples=2,
11                               iterations=10,
12                               confidence=0.999,
13                               threshold=1)
14
15# Create our model object
16model = line2d.Line2D()
17
18# Get the inliers
19inliers = pyransac.find_inliers(points=data,
20                                model=model,
21                                params=params)
22
23# Compare the data sets
24print(data)
25print(inliers)

Custom Data Models

All data models are derived from the Model base class. This class defines an interface consisting of two functions: make_model and calc_error. The make_model function generates a data model from a set of data points. The calc_error function calculates the error between a data point and the generated model. See the Model reference for more information.

You can define custom data models by extending the Model class. pyransac provides the following built-in data models:

  • Line2D — a 2-dimensional line model

Table of Contents

Indices and Tables