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
Nested ClassesModifier and TypeClassDescriptionstatic classDescribes a model and RANSAC fit parameters for specific type of object. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected Objectprotected int[]protected intprotected int[]protected intprotected List<RansacMulti.ObjectType>protected Randomprotected longprotected int -
Constructor Summary
ConstructorsConstructorDescriptionRansacMulti(long randSeed, int maxIterations, List<RansacMulti.ObjectType> objectTypes, Class<Point> typePoint) Creates a new instance of the ransac algorithm. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanChecks to see if it should stop the RANSAC iterations.doubleReturns the metric used to evaluate the quality of fit.intintgetInputIndex(int matchIndex) For an item in the match set, return the index of the item in the original input set.intA set of points which match the provided parameters.intintThis is the minimum number of observations which can be input and produce a valid model.intIndicates 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 voidinitialize(List<Point> dataSet) Initialize internal data structures before performing RANSAC iterationsbooleanFinds 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.voidreset()Resets the model matcher to its original state.protected <Model> voidselectMatchSet(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 voidsetBestModel(Object param) Turns the current candidates into the best ones.voidsetMaxIterations(int maxIterations) voidsetSampleSize(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:
processin 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:ModelMatcherA set of points which match the provided parameters.- Specified by:
getMatchSetin interfaceModelMatcher<Object,Point> - Returns:
- List of points in the match set.
-
getInputIndex
public int getInputIndex(int matchIndex) Description copied from interface:ModelMatcherFor an item in the match set, return the index of the item in the original input set.- Specified by:
getInputIndexin 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:ModelMatcherReturns 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:
getFitQualityin interfaceModelMatcher<Object,Point> - Returns:
- Quality of fit to matched set of points
-
getModelParameters
Description copied from interface:ModelMatcherModel for the match set- Specified by:
getModelParametersin interfaceModelMatcher<Object,Point> - Returns:
- model.
-
getModelIndex
public int getModelIndex()Description copied from interface:ModelMatcherMultiIndicates 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:
getModelIndexin 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:ModelMatcherThis is the minimum number of observations which can be input and produce a valid model.- Specified by:
getMinimumSizein interfaceModelMatcher<Object,Point> - Returns:
- Minimum number of sample points
-
reset
public void reset()Description copied from interface:ModelMatcherResets the model matcher to its original state. This means that given identical inputs it would produce the same outputs- Specified by:
resetin 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:ModelMatcherReturns a class for the input point object- Specified by:
getPointTypein interfaceModelMatcher<Object,Point>
-
getModelType
Description copied from interface:ModelMatcherReturns a class for the input point object- Specified by:
getModelTypein interfaceModelMatcher<Object,Point>
-