Giter VIP home page Giter VIP logo

learn-ransac's Introduction

learn-ransac

Learning about the different uses of RANSAC: Ransom Sample Consensus.

RANSAC is an interative method for estimating the parameters of a model from data that contains outliers.

API

from ransac import RansacEstimator

# estimate with RANSAC
ransac = RansacEstimator(
    min_samples=3,
    residual_threshold=0.001,
    max_trials=1000,
)
ret = ransac.fit(Procrustes(), [src_pc, dst_pc])

# extract best values
transform4x4_ransac = ret["best_params"]
mse_ransac = ret["best_residual"]
inliers_ransac = ret["best_inliers"]

2D Linear Regression (Ordinary Least Squares)

Code

As a toy example, we'll be corrupting a linear function of x with random outliers. Then we'll plot the predicted line from RANSAC and linear regression.

Drawing

Notice how the line determined by linear regression is influenced by the outliers. On the other hand, the line found by RANSAC is able to detect outliers (based on the threshold parameter) and thus more closely fits the data.

Rigid Transform Estimation

Code

Suppose we are given two point clouds and we would like to estimate the rigid transformation that aligns the first point cloud to the other.

In the regular setting, we assume the point correspondences between both point clouds are correct and compute the optimal rigid transform using SVD. This is known as the Orthogonal Procrustes Problem.

But what happens if we have some outliers, i.e. bad point correspondences? This can happen for instance when calibrating a camera and a bad checkerboard center is detected. The answer ... RANSAC!

Drawing Drawing

In the figure above, the red points correspond to explicitly corrupted correspondences. On the left, we have the rigid transform computed the regular way, without using RANSAC. The blue and orange points are supposed to be superimposed. Notice how the outliers have affected the transformation and there is a slight offset between all points. On the right is the result of RANSAC + Procrustes. The blue points now completely superimpose the orange ones (not visible anymore) and are not affected by the red outliers.

Point Cloud Normal Vector Estimation

Code

Suppose we are given a 3D point cloud and we would like to compute a normal vector associated with every 3D point in the cloud. That is, we want to estimate the normal of a plane tangent to each point in the cloud. This problem is thus equivalent to fitting a plane to each point (in the neighborhood of the point) using least squares. It turns out that the normal vector that minimizes the sum of squared distances between each point and the best-fitting plane is the left singular vector associated with the smallest singular value (SVD to the rescue).

We can combine normal estimation with RANSAC to reduce the effect of outlier points. This is especially useful when the point cloud is very noisy or wavy.

Drawing Drawing

Note: With the current demo point cloud, it doesn't seem like RANSAC offers any performance advantage and it is significantly slower than the non-RANSAC variant. I'll have to test it out with more noisy point clouds.

References

learn-ransac's People

Contributors

kevinzakka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.