Class RansacMulti<Point>
java.lang.Object
org.ddogleg.fitting.modelset.ransac.RansacMulti<Point>
- All Implemented Interfaces:
ModelMatcher<Object,
,Point> 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.
checkExitIteration()
: Override to provide custom logic for when the RANSAC iteration should stopselectMatchSet(java.util.List<Point>, org.ddogleg.fitting.modelset.DistanceFromModel<Model, Point>, double, Model)
: Override to provide custom for how the inlier set is found. Be sure to set up matchToInput[] correctly.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Describes a model and RANSAC fit parameters for specific type of object. -
Field Summary
Modifier and TypeFieldDescriptionprotected int
protected Object
protected int[]
protected int
protected int[]
protected int
protected List<RansacMulti.ObjectType>
protected Random
protected long
protected int
-
Constructor Summary
ConstructorDescriptionRansacMulti
(long randSeed, int maxIterations, List<RansacMulti.ObjectType> objectTypes, Class<Point> typePoint) Creates a new instance of the ransac algorithm. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Checks to see if it should stop the RANSAC iterations.double
Returns the metric used to evaluate the quality of fit.int
int
getInputIndex
(int matchIndex) For an item in the match set, return the index of the item in the original input set.int
A set of points which match the provided parameters.int
int
This is the minimum number of observations which can be input and produce a valid model.int
Indicates which model was found to best fit the points.Model for the match setReturns a class for the input point objectReturns a class for the input point objectprotected void
initialize
(List<Point> dataSet) Initialize internal data structures before performing RANSAC iterationsboolean
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.void
reset()
Resets the model matcher to its original state.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.protected void
setBestModel
(Object param) Turns the current candidates into the best ones.void
setMaxIterations
(int maxIterations) void
setSampleSize
(int sampleSize) Override the number of points that are sampled and used to generate models.
-
Field Details
-
sampleSize
protected int sampleSize -
rand
-
randSeed
protected long randSeed -
candidatePoints
-
bestFitPoints
-
objectTypes
-
objectParam
-
objectCandidateParam
-
bestFitParam
-
bestFitModelIndex
protected int bestFitModelIndex -
dataSet
-
iteration
protected int iteration -
maxIterations
protected int maxIterations -
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 invokesetSampleSize(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 detecttypePoint
- Class of Point
-
-
Method Details
-
process
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 interfaceModelMatcher<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
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
Turns the current candidates into the best ones. -
getMatchSet
Description copied from interface:ModelMatcher
A set of points which match the provided parameters.- Specified by:
getMatchSet
in interfaceModelMatcher<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 interfaceModelMatcher<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 interfaceModelMatcher<Object,
Point> - Returns:
- Quality of fit to matched set of points
-
getModelParameters
Description copied from interface:ModelMatcher
Model for the match set- Specified by:
getModelParameters
in interfaceModelMatcher<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 interfaceModelMatcherMulti<Point>
- Returns:
- Index of selected model.
-
getInlierSize
public int getInlierSize() -
getMaxIterations
public int getMaxIterations() -
setMaxIterations
public void setMaxIterations(int maxIterations) -
getCandidatePoints
-
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 interfaceModelMatcher<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 interfaceModelMatcher<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
Description copied from interface:ModelMatcher
Returns a class for the input point object- Specified by:
getPointType
in interfaceModelMatcher<Object,
Point>
-
getModelType
Description copied from interface:ModelMatcher
Returns a class for the input point object- Specified by:
getModelType
in interfaceModelMatcher<Object,
Point>
-