Click or drag to resize
Accord.NET (logo)

RansacHomographyEstimator Class

RANSAC Robust Homography Matrix Estimator.
Inheritance Hierarchy

Namespace:  Accord.Imaging
Assembly:  Accord.Vision (in Accord.Vision.dll) Version: 3.7.0
public class RansacHomographyEstimator
Request Example View Source

The RansacHomographyEstimator type exposes the following members.

Public methodRansacHomographyEstimator
Creates a new RANSAC homography estimator.
Public propertyInliers
Gets the final set of inliers detected by RANSAC.
Public propertyRansac
Gets the RANSAC estimator used.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodEstimate(PointF)
Matches two sets of points using RANSAC.
Public methodEstimate(IntPoint)
Matches two sets of points using RANSAC.
Public methodEstimate(Point)
Matches two sets of points using RANSAC.
Public methodEstimate(PointF, PointF)
Matches two sets of points using RANSAC.
Public methodEstimate(IntPoint, IntPoint)
Matches two sets of points using RANSAC.
Public methodEstimate(Point, Point)
Matches two sets of points using RANSAC.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Extension Methods
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodToT
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)

Fitting a homography using RANSAC is pretty straightforward. Being a iterative method, in a single iteration a random sample of four correspondences is selected from the given correspondence points and a homography H is then computed from those points.

The original points are then transformed using this homography and their distances to where those transforms should be is then computed and matching points can classified as inliers and non-matching points as outliers.

After a given number of iterations, the iteration which produced the largest number of inliers is then selected as the best estimation for H.


  • E. Dubrofsky. Homography Estimation. Master thesis. Available on:

// Let's start with two pictures that have been
// taken from slightly different points of view:
Bitmap img1 = Resources.dc_left;
Bitmap img2 = Resources.dc_right;

// Those pictures are shown below:
ImageBox.Show(img1, PictureBoxSizeMode.Zoom, 640, 480);
ImageBox.Show(img2, PictureBoxSizeMode.Zoom, 640, 480);
// Step 1: Detect feature points using Surf Corners Detector
var surf = new SpeededUpRobustFeaturesDetector();

var points1 = surf.ProcessImage(img1);
var points2 = surf.ProcessImage(img2);

// Step 2: Match feature points using a k-NN
var matcher = new KNearestNeighborMatching(5);
var matches = matcher.Match(points1, points2);

// Step 3: Create the matrix using a robust estimator
var ransac = new RansacHomographyEstimator(0.001, 0.99);
MatrixH homographyMatrix = ransac.Estimate(matches);

// Step 4: Project and blend using the homography
Blend blend = new Blend(homographyMatrix, img1);

// Compute the blending algorithm
Bitmap result = blend.Apply(img2);

// Show on screen
ImageBox.Show(result, PictureBoxSizeMode.Zoom, 640, 480);

The resulting image is shown below.

See Also