GithubHelp home page GithubHelp logo

ransac's Introduction

RANSAC

A simple python based implementation of the RANSAC algorithm. This implementation attempts to fit a line or a curve to a dataset containing outliers that could throw off a least squares approach.

Requirements

There are no additional libraries needed to use the linear.py module. It should run under both Python 2 and 3. To run the linear_demo.py module, you will need the numpy and matplotlib libraries. You can install them with pip:

pip install numpy matplotlib

To use the quadratic.py module, you will need the numpy and scipy libraries. It should run under both Python 2 and 3. To run the quadratic demo you will also need matplotlib. You can install them with pip:

pip install numpy scipy matplotlib

How to use

Linear

Simply import the linear module, and then call the compute function:

import ransac.linear

result = ransac.linear.compute(input_points, max_distance, max_iterations, ratio)

chosen_points = result[0]
slope = result[1]
y_int = result[2]
inliers = result[3]
outliers = result[4]

Input values:

  • input_points: A list of coordinate pairs of the data points to be processed
  • max_distance: The furthest a point can be from the model line while still being considered an inlier
  • max_iterations: The number most number of times to run the algorithm before terminating, even if an optimal line has not been found
  • ratio: The percentage of point that are inliers for a model line to be considered a good fit

Return values:

  • chosen_points: A list of the coordinate pairs of the two points selected to form the model line
  • slope: The slope of the model line
  • inliers: A list of coordinate pairs of the inlier points
  • outliers: A list of coordinate pairs of the outlier points

Quadratic

Simply import the quadratic module, and then call the compute function:

import ransac.quadratic

result = ransac.quadratic.compute(input_points, max_distance, max_iterations, ratio)

chosen_points = result[0]
a = result[1]
b = result[2]
c = result[3]
inliers = result[4]
outliers = result[5]

Input values:

  • input_points: A list of coordinate pairs of the data points to be processed
  • max_distance: The furthest a point can be from the model line while still being considered an inlier
  • max_iterations: The number most number of times to run the algorithm before terminating, even if an optimal line has not been found
  • ratio: The percentage of point that are inliers for a model line to be considered a good fit

Return values:

  • chosen_points: A list of the coordinate pairs of the two points selected to form the model line
  • a: The A parameter in y = Ax^2 + Bx + C
  • b: The B parameter in y = Ax^2 + Bx + C
  • c: The C parameter in y = Ax^2 + Bx + C
  • inliers: A list of coordinate pairs of the inlier points
  • outliers: A list of coordinate pairs of the outlier points

Demonstration

Linear

To see a visual demonstration of the algorithm's line fitting iterative approach, simply run:

./linear_demo.py

The default will be to terminate after 10 cycles of the algorithm, which can be changed by the MAX_ITERATIONS parameter at the top of the file. After every iteration, a graph including the chosen model line, inliers, and outliers will be produced in the "Output" directory. This directory can be changed through the OUTPUT_DIR parameter at the top of the file.

Quadratic

To see a visual demonstration of the algorithm's curve fitting iterative approach, simply run:

./quadratic_demo.py

The default will be to terminate after 20 cycles of the algorithm, which can be changed by the MAX_ITERATIONS parameter at the top of the file. After every iteration, a graph including the chosen model curve, inliers, and outliers will be produced in the "Output" directory. This directory can be changed through the OUTPUT_DIR parameter at the top of the file.

ransac's People

Contributors

joshuaspring9 avatar

Stargazers

 avatar Alexander avatar

Watchers

 avatar

Forkers

fatencherni

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.