I
- type of independent dataD
- type of dependent dataM
- concrete type of model learnedpublic class RANSAC<I,D,M extends EstimatableModel<I,D>> extends Object implements RobustModelFitting<I,D,M>
For fitting noisy data consisting of inliers and outliers to a model.
Assume: M data items required to estimate parameter x N data items in total
1.) select M data items at random
2.) estimate parameter x
3.) find how many of the N data items fit (i.e. have an error less than a
threshold or pass some check) x within tolerence tol, call this K
4.) if K is large enough (bigger than numItems) accept x and exit with
success
5.) repeat 1..4 nIter times
6.) fail - no good x fit of data
In this implementation, the conditions that control the iterations are configurable. In addition, the best matching model is always stored, even if the fitData() method returns false.
Modifier and Type | Class and Description |
---|---|
static class |
RANSAC.BestFitStoppingCondition
Stopping condition that allows the RANSAC algorithm to run until all the
iterations have been exhausted.
|
static class |
RANSAC.NumberInliersStoppingCondition
Stopping condition that tests the number of matches against a threshold.
|
static class |
RANSAC.PercentageInliersStoppingCondition
Stopping condition that tests the number of matches against a percentage
threshold of the whole data.
|
static class |
RANSAC.ProbabilisticMinInliersStoppingCondition
Stopping condition that tests the number of matches against a percentage
threshold of the whole data.
|
static interface |
RANSAC.StoppingCondition
Interface for classes that can control RANSAC iterations
|
Modifier and Type | Field and Description |
---|---|
protected List<IndependentPair<I,D>> |
bestModelInliers |
protected List<IndependentPair<I,D>> |
bestModelOutliers |
protected DistanceCheck |
dc |
protected ResidualCalculator<I,D,M> |
errorModel |
protected boolean |
improveEstimate |
protected List<IndependentPair<I,D>> |
inliers |
protected M |
model |
protected List<? extends IndependentPair<I,D>> |
modelConstructionData |
protected int |
nIter |
protected List<IndependentPair<I,D>> |
outliers |
protected CollectionSampler<IndependentPair<I,D>> |
sampler |
protected RANSAC.StoppingCondition |
stoppingCondition |
Constructor and Description |
---|
RANSAC(M model,
ResidualCalculator<I,D,M> errorModel,
DistanceCheck dc,
int nIterations,
RANSAC.StoppingCondition stoppingCondition,
boolean impEst)
Create a RANSAC object with uniform random sampling for creating the
subsets
|
RANSAC(M model,
ResidualCalculator<I,D,M> errorModel,
DistanceCheck dc,
int nIterations,
RANSAC.StoppingCondition stoppingCondition,
boolean impEst,
CollectionSampler<IndependentPair<I,D>> sampler)
Create a RANSAC object
|
RANSAC(M model,
ResidualCalculator<I,D,M> errorModel,
double errorThreshold,
int nIterations,
RANSAC.StoppingCondition stoppingCondition,
boolean impEst)
Create a RANSAC object with uniform random sampling for creating the
subsets
|
RANSAC(M model,
ResidualCalculator<I,D,M> errorModel,
double errorThreshold,
int nIterations,
RANSAC.StoppingCondition stoppingCondition,
boolean impEst,
CollectionSampler<IndependentPair<I,D>> sampler)
Create a RANSAC object
|
Modifier and Type | Method and Description |
---|---|
boolean |
fitData(List<? extends IndependentPair<I,D>> data)
Attempt to fit the given data to the model.
|
List<? extends IndependentPair<I,D>> |
getInliers() |
int |
getMaxIterations() |
M |
getModel() |
List<? extends IndependentPair<I,D>> |
getModelConstructionData() |
List<? extends IndependentPair<I,D>> |
getOutliers() |
boolean |
isImproveEstimate() |
int |
numItemsToEstimate() |
void |
setImproveEstimate(boolean improveEstimate)
Set whether RANSAC should attempt to improve the model using all inliers
as data
|
void |
setMaxIterations(int nIter)
Set the maximum number of allowed iterations
|
void |
setModel(M model)
Set the underlying model being fitted
|
void |
setModelConstructionData(List<? extends IndependentPair<I,D>> modelConstructionData)
Set the data used to construct the model
|
protected M extends EstimatableModel<I,D> model
protected ResidualCalculator<I,D,M extends EstimatableModel<I,D>> errorModel
protected DistanceCheck dc
protected int nIter
protected boolean improveEstimate
protected List<IndependentPair<I,D>> inliers
protected List<IndependentPair<I,D>> outliers
protected List<IndependentPair<I,D>> bestModelInliers
protected List<IndependentPair<I,D>> bestModelOutliers
protected RANSAC.StoppingCondition stoppingCondition
protected List<? extends IndependentPair<I,D>> modelConstructionData
protected CollectionSampler<IndependentPair<I,D>> sampler
public RANSAC(M model, ResidualCalculator<I,D,M> errorModel, double errorThreshold, int nIterations, RANSAC.StoppingCondition stoppingCondition, boolean impEst)
model
- Model object with which to fit dataerrorModel
- object to compute the error of the modelerrorThreshold
- the threshold below which error is deemed acceptable for a fitnIterations
- Maximum number of allowed iterations (L)stoppingCondition
- the stopping conditionimpEst
- True if we want to perform a final fitting of the model with
all inliers, false otherwisepublic RANSAC(M model, ResidualCalculator<I,D,M> errorModel, DistanceCheck dc, int nIterations, RANSAC.StoppingCondition stoppingCondition, boolean impEst)
model
- Model object with which to fit dataerrorModel
- object to compute the error of the modeldc
- the distance check that tests whether a point with given error
from the error model should be considered an inliernIterations
- Maximum number of allowed iterations (L)stoppingCondition
- the stopping conditionimpEst
- True if we want to perform a final fitting of the model with
all inliers, false otherwisepublic RANSAC(M model, ResidualCalculator<I,D,M> errorModel, double errorThreshold, int nIterations, RANSAC.StoppingCondition stoppingCondition, boolean impEst, CollectionSampler<IndependentPair<I,D>> sampler)
model
- Model object with which to fit dataerrorModel
- object to compute the error of the modelerrorThreshold
- the threshold below which error is deemed acceptable for a fitnIterations
- Maximum number of allowed iterations (L)stoppingCondition
- the stopping conditionimpEst
- True if we want to perform a final fitting of the model with
all inliers, false otherwisesampler
- the sampling algorithm for selecting random subsetspublic RANSAC(M model, ResidualCalculator<I,D,M> errorModel, DistanceCheck dc, int nIterations, RANSAC.StoppingCondition stoppingCondition, boolean impEst, CollectionSampler<IndependentPair<I,D>> sampler)
model
- Model object with which to fit dataerrorModel
- object to compute the error of the modeldc
- the distance check that tests whether a point with given error
from the error model should be considered an inliernIterations
- Maximum number of allowed iterations (L)stoppingCondition
- the stopping conditionimpEst
- True if we want to perform a final fitting of the model with
all inliers, false otherwisesampler
- the sampling algorithm for selecting random subsetspublic boolean fitData(List<? extends IndependentPair<I,D>> data)
ModelFitting
fitData
in interface ModelFitting<I,D,M extends EstimatableModel<I,D>>
data
- Data to be fittedpublic List<? extends IndependentPair<I,D>> getInliers()
getInliers
in interface RobustModelFitting<I,D,M extends EstimatableModel<I,D>>
public List<? extends IndependentPair<I,D>> getOutliers()
getOutliers
in interface RobustModelFitting<I,D,M extends EstimatableModel<I,D>>
public int getMaxIterations()
public void setMaxIterations(int nIter)
nIter
- maximum number of allowed iterationspublic M getModel()
getModel
in interface ModelFitting<I,D,M extends EstimatableModel<I,D>>
public void setModel(M model)
model
- the modelpublic boolean isImproveEstimate()
public void setImproveEstimate(boolean improveEstimate)
improveEstimate
- should RANSAC attempt to improve the model using all inliers
as datapublic void setModelConstructionData(List<? extends IndependentPair<I,D>> modelConstructionData)
modelConstructionData
- public List<? extends IndependentPair<I,D>> getModelConstructionData()
public int numItemsToEstimate()
numItemsToEstimate
in interface ModelFitting<I,D,M extends EstimatableModel<I,D>>