Class RansacMulti<Point>

java.lang.Object
org.ddogleg.fitting.modelset.ransac.RansacMulti<Point>
All Implemented Interfaces:
ModelMatcher<Object,Point>, ModelMatcherMulti<Point>

public class RansacMulti<Point> extends Object implements ModelMatcherMulti<Point>

Modification of RANSAC that finds the best fit model and model parameters to a set of data. A model is a mathematical description of a specific object type (e.g. circle, square) and model parameters is the description (e.g. radius and center point for a circle). The minimum (or user specified) set of points is drawn from the set of all points. Then for each model parameters are estimated. The model and parameter pair with the largest inliers set is returned.

To change the default behavior of the class for specific applications the child class can override internal functions. Suggestions are shown below.

  • Field Details

    • sampleSize

      protected int sampleSize
    • rand

      protected Random rand
    • randSeed

      protected long randSeed
    • candidatePoints

      protected List<Point> candidatePoints
    • bestFitPoints

      protected List<Point> bestFitPoints
    • objectTypes

      protected List<RansacMulti.ObjectType> objectTypes
    • objectParam

      protected List<Object> objectParam
    • objectCandidateParam

      protected List<Object> objectCandidateParam
    • bestFitParam

      protected Object bestFitParam
    • bestFitModelIndex

      protected int bestFitModelIndex
    • dataSet

      protected List<Point> dataSet
    • iteration

      protected int iteration
    • maxIterations

      protected int maxIterations
    • initialSample

      protected FastArray<Point> initialSample
    • matchToInput

      protected int[] matchToInput
    • bestMatchToInput

      protected int[] bestMatchToInput
  • Constructor Details

    • RansacMulti

      public RansacMulti(long randSeed, int maxIterations, List<RansacMulti.ObjectType> objectTypes, Class<Point> typePoint)
      Creates a new instance of the ransac algorithm. The number of points sampled will default to the minimum number. To override this default invoke setSampleSize(int).
      Parameters:
      randSeed - The random seed used by the random number generator.
      maxIterations - The maximum number of iterations the RANSAC algorithm will perform.
      objectTypes - Description of the different types of objects it can detect
      typePoint - Class of Point
  • Method Details

    • process

      public boolean process(List<Point> _dataSet)
      Finds a set of points from the provided list that are a good fit for the internal model and computes the fit parameters for the model.
      Specified by:
      process in interface ModelMatcher<Object,Point>
      Parameters:
      _dataSet - Set of points (with noise) that are to be fit.
      Returns:
      true if it successfully found a solution or false if not.
    • checkExitIteration

      protected boolean checkExitIteration()
      Checks to see if it should stop the RANSAC iterations. A child class can override this class to perform a custom behavior. The default code is shown below:
       iteration < maxIterations && bestFitPoints.size() != dataSet.size()
       
      Returns:
      if true RANSAC should continue iterating if false then RANSAC will stop.
    • initialize

      protected void initialize(List<Point> dataSet)
      Initialize internal data structures before performing RANSAC iterations
    • selectMatchSet

      protected <Model> void selectMatchSet(List<Point> dataSet, DistanceFromModel<Model,Point> modelDistance, double threshold, Model param)
      Exhaustively searches through the list of points contained in 'dataSet' for the set of inliers which match the provided model. It keeps track of the mapping between the index of the inlier list and the 'dataSet' list using the matchToInput[] array. If there is no corresponding (can't happen by default) match then -1 should be set in matchToInput..
      Parameters:
      modelDistance - Computes
    • setBestModel

      protected void setBestModel(Object param)
      Turns the current candidates into the best ones.
    • getMatchSet

      public List<Point> getMatchSet()
      Description copied from interface: ModelMatcher
      A set of points which match the provided parameters.
      Specified by:
      getMatchSet in interface ModelMatcher<Object,Point>
      Returns:
      List of points in the match set.
    • getInputIndex

      public int getInputIndex(int matchIndex)
      Description copied from interface: ModelMatcher
      For an item in the match set, return the index of the item in the original input set.
      Specified by:
      getInputIndex in interface ModelMatcher<Object,Point>
      Parameters:
      matchIndex - Index of an element in the match set.
      Returns:
      Index of the same element in the original input list.
    • getFitQuality

      public double getFitQuality()
      Description copied from interface: ModelMatcher
      Returns the metric used to evaluate the quality of fit. Meaning is implementation specific. Larger or smaller values could be preferred depending on implementation..
      Specified by:
      getFitQuality in interface ModelMatcher<Object,Point>
      Returns:
      Quality of fit to matched set of points
    • getModelParameters

      public Object getModelParameters()
      Description copied from interface: ModelMatcher
      Model for the match set
      Specified by:
      getModelParameters in interface ModelMatcher<Object,Point>
      Returns:
      model.
    • getModelIndex

      public int getModelIndex()
      Description copied from interface: ModelMatcherMulti
      Indicates which model was found to best fit the points. The index is implementation specific and is likely to refer to the index inside a list.
      Specified by:
      getModelIndex in interface ModelMatcherMulti<Point>
      Returns:
      Index of selected model.
    • getInlierSize

      public int getInlierSize()
    • getMaxIterations

      public int getMaxIterations()
    • setMaxIterations

      public void setMaxIterations(int maxIterations)
    • getCandidatePoints

      protected List<Point> getCandidatePoints()
    • getInitialSample

      protected FastArray<Point> getInitialSample()
    • getMinimumSize

      public int getMinimumSize()
      Description copied from interface: ModelMatcher
      This is the minimum number of observations which can be input and produce a valid model.
      Specified by:
      getMinimumSize in interface ModelMatcher<Object,Point>
      Returns:
      Minimum number of sample points
    • reset

      public void reset()
      Description copied from interface: ModelMatcher
      Resets the model matcher to its original state. This means that given identical inputs it would produce the same outputs
      Specified by:
      reset in interface ModelMatcher<Object,Point>
    • setSampleSize

      public void setSampleSize(int sampleSize)
      Override the number of points that are sampled and used to generate models. If this value is not set it defaults to the minimum number.
      Parameters:
      sampleSize - Number of sample points.
    • getIteration

      public int getIteration()
    • getPointType

      public Class<Point> getPointType()
      Description copied from interface: ModelMatcher
      Returns a class for the input point object
      Specified by:
      getPointType in interface ModelMatcher<Object,Point>
    • getModelType

      public Class<Object> getModelType()
      Description copied from interface: ModelMatcher
      Returns a class for the input point object
      Specified by:
      getModelType in interface ModelMatcher<Object,Point>