Package com.irurueta.numerical.robust
Class PROSACRobustEstimator<T>
java.lang.Object
com.irurueta.numerical.robust.RobustEstimator<T>
com.irurueta.numerical.robust.PROSACRobustEstimator<T>
- Type Parameters:
T
- type of object to be estimated.
This class implements PROSAC (PROgressive random SAmple Consensus) algorithm
to robustly estimate a data model.
This algorithm is an improvement over RANSAC that can be used whenever a
certain measure of quality is known for each sample of data.
The measure of quality does not need to be precise, only needs to give a
certain idea whether a given sample is likely to be better than another one
(by having a higher quality score).
Whenever RANSAC is being used but quality of measures is known, PROSAC should
be used instead, since this algorithm offers a result with a comparable
precision to that obtained with RANSAC but having a much smaller
computational cost.
The large improvement in computational cost is achieved thanks to the fact
that by taking into account the quality measures, sub-samples can be
prioritized so that more likely to be inliers are picked first.
This implementation is based on: http://devernay.free.fr/vision/src/prosac.c
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Contains data related to estimated inliers. -
Field Summary
FieldsModifier and TypeFieldDescriptionData related to inliers found for best result.private T
Best solution that has been found so far during an estimation.private double
beta is the probability that a match is declared inlier by mistake, i.e.static final double
Chi squared.private boolean
Indicates whether inliers must be computed and kept.private boolean
Indicates whether residuals must be computed and kept.private double
Amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).static final double
Defines the default value for beta, which is the probability that a match is declared inlier by mistake, i.e.static final boolean
Indicates that by default inliers will only be computed but not kept.static final boolean
Indicates that by default residuals will only be computed but not kept.static final double
Constant defining default confidence of the estimated result, which is 99%.static final double
Defines the default value for the maximum probability that a solution with more than inliersNStar in U_nStar exist and was not found after k samples.static final int
Default maximum allowed number of iterations.static final double
Default maximum allowed outliers proportion in the input data.private double
eta0 is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).static final double
Maximum allowed value for beta.static final double
Maximum allowed confidence value.static final double
Maximum allowed value for eta0.static final double
Maximum allowed value for maximum allowed outliers proportion in the input dataprivate int
Maximum allowed number of iterations.private double
In this implementation, PROSAC won't stop before having reached the corresponding inliers rate on the complete data set.static final double
Minimum allowed value for beta.static final double
Minimum allowed confidence value.static final double
Minimum allowed value for eta0.static final int
Minimum allowed number of iterations.static final double
Minimum allowed value for maximum allowed outliers proportion in the input data.static final double
Minimum allowed threshold to determine inliers.private int
Number of iterations to be done to obtain required confidence.private SubsetSelector
Instance in charge of picking random subsets of samples.Fields inherited from class com.irurueta.numerical.robust.RobustEstimator
DEFAULT_PROGRESS_DELTA, listener, locked, MAX_PROGRESS_DELTA, MIN_PROGRESS_DELTA, progressDelta
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.PROSACRobustEstimator
(PROSACRobustEstimatorListener<T> listener) Constructor with listener. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> int
computeInliers
(T iterResult, double threshold, BitSet inliers, int totalSamples, PROSACRobustEstimatorListener<T> listener, double[] residuals) Computes inliers data for current iteration.private static int
computeIterations
(double probInlier, int subsetSize, double confidence) Computes number of required iterations to achieve required confidence with current probability of inlier and sample subset size.private static int[]
computeSortedQualityIndices
(double[] qualityScores) Obtains indices of samples corresponding to samples ordered in descending quality scores.estimate()
Robustly estimates an instance of T.Gets data related to inliers found for best result.Returns best solution that has been found so far during an estimation.double
getBeta()
Returns beta, which is the probability that a match is declared inlier by mistake, i.e.double
Returns amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).double
getEta0()
Return eta0, which is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).Returns data about inliers once estimation has been done.int
Maximum allowed number of iterations.double
Returns maximum allowed outliers proportion in the input data.Returns method being used for robust estimation.int
Returns number of iterations to be done to obtain required confidence.private static int
imin
(int subsetSize, int sampleSize, double beta) Non randomness states that i-m (where i is the cardinal of the set of inliers for a wrong model) follows the binomial distribution B(n,beta).boolean
Indicates whether inliers must be computed and kept.boolean
Indicates whether residuals must be computed and kept.boolean
isReady()
Indicates if estimator is ready to start the estimation process.private static void
reverse
(int[] array) Reverses provided array.void
setBeta
(double beta) Sets beta, which is the probability that a match is declared inlier by mistake, i.e.void
setComputeAndKeepInliersEnabled
(boolean computeAndKeepInliers) Specifies whether inliers must be computed and kept.void
setComputeAndKeepResidualsEnabled
(boolean computeAndKeepResiduals) Specifies whether residuals must be computed and kept.void
setConfidence
(double confidence) Sets amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).void
setEta0
(double eta0) Sets eta0, which is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).void
setMaxIterations
(int maxIterations) Sets maximum allowed number of iterations.void
setMaxOutliersProportion
(double maxOutliersProportion) Sets maximum allowed outliers proportion in the input data.private static void
transformIndices
(int[] subsetIndices, int[] sortedIndices, int[] transformedSubsetIndices) Transforms indices picked by the subset selector into the indices where samples are actually localed by taking into account their original position before sorting quality scores.Methods inherited from class com.irurueta.numerical.robust.RobustEstimator
getListener, getProgressDelta, isListenerAvailable, isLocked, setListener, setProgressDelta
-
Field Details
-
DEFAULT_CONFIDENCE
public static final double DEFAULT_CONFIDENCEConstant defining default confidence of the estimated result, which is 99%. This means that with a probability of 99% estimation will be accurate because chosen sub-samples will be inliers.- See Also:
-
DEFAULT_MAX_ITERATIONS
public static final int DEFAULT_MAX_ITERATIONSDefault maximum allowed number of iterations.- See Also:
-
MIN_CONFIDENCE
public static final double MIN_CONFIDENCEMinimum allowed confidence value.- See Also:
-
MAX_CONFIDENCE
public static final double MAX_CONFIDENCEMaximum allowed confidence value.- See Also:
-
MIN_ITERATIONS
public static final int MIN_ITERATIONSMinimum allowed number of iterations.- See Also:
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDMinimum allowed threshold to determine inliers.- See Also:
-
DEFAULT_MAX_OUTLIERS_PROPORTION
public static final double DEFAULT_MAX_OUTLIERS_PROPORTIONDefault maximum allowed outliers proportion in the input data. This is used do determine the number of required iterations.- See Also:
-
MIN_MAX_OUTLIERS_PROPORTION
public static final double MIN_MAX_OUTLIERS_PROPORTIONMinimum allowed value for maximum allowed outliers proportion in the input data.- See Also:
-
MAX_MAX_OUTLIERS_PROPORTION
public static final double MAX_MAX_OUTLIERS_PROPORTIONMaximum allowed value for maximum allowed outliers proportion in the input data- See Also:
-
DEFAULT_ETA0
public static final double DEFAULT_ETA0Defines the default value for the maximum probability that a solution with more than inliersNStar in U_nStar exist and was not found after k samples.- See Also:
-
MIN_ETA0
public static final double MIN_ETA0Minimum allowed value for eta0.- See Also:
-
MAX_ETA0
public static final double MAX_ETA0Maximum allowed value for eta0.- See Also:
-
DEFAULT_BETA
public static final double DEFAULT_BETADefines the default value for beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface. The inlier surface is a disc with radius 1.96s for homography/displacement computation, or a band with width 1.96*s*2 for epipolar geometry (s is the detection noise), and the total surface is the surface of the image.- See Also:
-
MIN_BETA
public static final double MIN_BETAMinimum allowed value for beta.- See Also:
-
MAX_BETA
public static final double MAX_BETAMaximum allowed value for beta.- See Also:
-
CHI_SQUARED
public static final double CHI_SQUAREDChi squared.- See Also:
-
DEFAULT_COMPUTE_AND_KEEP_INLIERS
public static final boolean DEFAULT_COMPUTE_AND_KEEP_INLIERSIndicates that by default inliers will only be computed but not kept.- See Also:
-
DEFAULT_COMPUTE_AND_KEEP_RESIDUALS
public static final boolean DEFAULT_COMPUTE_AND_KEEP_RESIDUALSIndicates that by default residuals will only be computed but not kept.- See Also:
-
confidence
private double confidenceAmount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%). The amount of confidence indicates the probability that the estimated result is correct. Usually this value will be close to 1.0, but not exactly 1.0. -
maxIterations
private int maxIterationsMaximum allowed number of iterations. When the maximum number of iterations is exceeded, result will not be available, however an approximate result will be available for retrieval. -
maxOutliersProportion
private double maxOutliersProportionIn this implementation, PROSAC won't stop before having reached the corresponding inliers rate on the complete data set. Maximum allowed outliers proportion in the input data: used to compute nIters (can be as high as 0.95). -
eta0
private double eta0eta0 is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%). -
beta
private double betabeta is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface. The inlier surface is a disc with radius 1.96s for homography/displacement computation, or a band with width 1.96s*2 for epipolar geometry (s is the detection noise), and the total surface is the surface of the image YOU MUST ADJUST THIS VALUE, DEPENDING ON YOUR PROBLEM! -
subsetSelector
Instance in charge of picking random subsets of samples. -
nIters
private int nItersNumber of iterations to be done to obtain required confidence. -
bestResult
Best solution that has been found so far during an estimation. -
bestInliersData
Data related to inliers found for best result. -
computeAndKeepInliers
private boolean computeAndKeepInliersIndicates whether inliers must be computed and kept. -
computeAndKeepResiduals
private boolean computeAndKeepResidualsIndicates whether residuals must be computed and kept.
-
-
Constructor Details
-
PROSACRobustEstimator
public PROSACRobustEstimator()Constructor. -
PROSACRobustEstimator
Constructor with listener.- Parameters:
listener
- listener to be notified of events such as when estimation starts, ends or its progress significantly changes, as well as in charge of picking samples and doing per-iteration estimations.
-
-
Method Details
-
getConfidence
public double getConfidence()Returns amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%). The amount of confidence indicates the probability that the estimated result is correct. Usually this value will be close to 1.0, but not exactly 1.0.- Returns:
- amount of confidence as a value between 0.0 and 1.0.
-
setConfidence
Sets amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%). The amount of confidence indicates the probability that the estimated result is correct. Usually this value will be close to 1.0, but not exactly 1.0.- Parameters:
confidence
- confidence to be set as a value between 0.0 and 1.0.- Throws:
IllegalArgumentException
- if provided value is not between 0.0 and 1.0.LockedException
- if this estimator is locked because an estimation is being computed.
-
getMaxIterations
public int getMaxIterations()Maximum allowed number of iterations. When the maximum number of iterations is exceeded, result will not be available, however an approximate result will be available for retrieval.- Returns:
- maximum allowed number of iterations.
-
setMaxIterations
Sets maximum allowed number of iterations. When the maximum number of iterations is exceeded, result will not be available, however an approximate result will be available for retrieval.- Parameters:
maxIterations
- maximum allowed number of iterations to be set.- Throws:
IllegalArgumentException
- if provided value is less than 1.LockedException
- if this estimator is locked because an estimation is being computed.
-
getMaxOutliersProportion
public double getMaxOutliersProportion()Returns maximum allowed outliers proportion in the input data. This is used to compute number of iterations to be done (nIters). It typically can be as high as 0.95. Higher values, up to 1 are possible but not recommended. In this implementation, PROSAC won't stop before having reached the corresponding inliers rate on the complete data set.- Returns:
- maximum allowed outliers proportion in the input data.
-
setMaxOutliersProportion
Sets maximum allowed outliers proportion in the input data. This is used to compute number of iterations to be done (nIters). It typically can be as high as 0.95. Higher values, up to 1 are possible but not recommended. In this implementation, PROSAC won't stop before having reached the corresponding inliers rate on the complete data set.- Parameters:
maxOutliersProportion
- maximum allowed outliers proportion in the input data.- Throws:
IllegalArgumentException
- if provided value is less than 0.0 or greater than 1.0.LockedException
- if this estimator is locked because an estimation is being computed.
-
getEta0
public double getEta0()Return eta0, which is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).- Returns:
- eta0 value.
-
setEta0
Sets eta0, which is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).- Parameters:
eta0
- eta0 value to be set.- Throws:
IllegalArgumentException
- if provided value is less than 0.0 or greater than 1.0.LockedException
- if this estimator is locked because an estimation is being computed.
-
getBeta
public double getBeta()Returns beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface. The inlier surface is a disc with radius 1.96s for homography/displacement computation, or a band with width 1.96s*2 for epipolar geometry (s is the detection noise), and the total surface is the surface of the image YOU MUST ADJUST THIS VALUE, DEPENDING ON YOUR PROBLEM!- Returns:
- beta value.
-
setBeta
Sets beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface. The inlier surface is a disc with radius 1.96s for homography/displacement computation, or a band with width 1.96s*2 for epipolar geometry (s is the detection noise), and the total surface is the surface of the image YOU MUST ADJUST THIS VALUE, DEPENDING ON YOUR PROBLEM!- Parameters:
beta
- beta value to be set.- Throws:
IllegalArgumentException
- if provided value is less than 0.0 or greater than 1.0.LockedException
- if this estimator is locked because an estimation is being computed.
-
getNIters
public int getNIters()Returns number of iterations to be done to obtain required confidence. This does not need to be equal to the actual number of iterations the algorithm finally required to obtain a solution.- Returns:
- number of iterations to be done to obtain required confidence.
-
getBestResult
Returns best solution that has been found so far during an estimation.- Returns:
- best solution that has been found so far during an estimation.
-
getBestInliersData
Gets data related to inliers found for best result.- Returns:
- data related to inliers found for best result.
-
isComputeAndKeepInliersEnabled
public boolean isComputeAndKeepInliersEnabled()Indicates whether inliers must be computed and kept.- Returns:
- true if inliers must be computed and kept, false if inliers only need to be computed but not kept.
-
setComputeAndKeepInliersEnabled
Specifies whether inliers must be computed and kept.- Parameters:
computeAndKeepInliers
- true if inliers must be computed and kept, false if inliers only need to be computed but not kept.- Throws:
LockedException
- if estimator is locked.
-
isComputeAndKeepResidualsEnabled
public boolean isComputeAndKeepResidualsEnabled()Indicates whether residuals must be computed and kept.- Returns:
- true if residuals must be computed and kept, false if residuals only need to be computed but not kept.
-
setComputeAndKeepResidualsEnabled
public void setComputeAndKeepResidualsEnabled(boolean computeAndKeepResiduals) throws LockedException Specifies whether residuals must be computed and kept.- Parameters:
computeAndKeepResiduals
- true if residuals must be computed and kept, false if residuals only need to be computed but not kept.- Throws:
LockedException
- if estimator is locked.
-
isReady
public boolean isReady()Indicates if estimator is ready to start the estimation process.- Overrides:
isReady
in classRobustEstimator<T>
- Returns:
- true if ready, false otherwise.
-
estimate
Robustly estimates an instance of T.- Specified by:
estimate
in classRobustEstimator<T>
- Returns:
- estimated object.
- Throws:
LockedException
- if robust estimator is locked.NotReadyException
- if provided input data is not enough to start the estimation.RobustEstimatorException
- if estimation fails for any reason (i.e. numerical instability, no solution available, etc).
-
getInliersData
Returns data about inliers once estimation has been done.- Specified by:
getInliersData
in classRobustEstimator<T>
- Returns:
- data about inliers or null if estimation has not been done.
-
getMethod
Returns method being used for robust estimation.- Specified by:
getMethod
in classRobustEstimator<T>
- Returns:
- method being used for robust estimation.
-
transformIndices
private static void transformIndices(int[] subsetIndices, int[] sortedIndices, int[] transformedSubsetIndices) Transforms indices picked by the subset selector into the indices where samples are actually localed by taking into account their original position before sorting quality scores.- Parameters:
subsetIndices
- indices picked by the subset selector. These are positions after sorting. Must have the subset length.sortedIndices
- indices relating sorted positions to their original positions. Each position i-th in the array refers to the original position before sorting. Must have the number of samples length.transformedSubsetIndices
- array where result is stored. Must have the subset length.
-
computeInliers
private static <T> int computeInliers(T iterResult, double threshold, BitSet inliers, int totalSamples, PROSACRobustEstimatorListener<T> listener, double[] residuals) Computes inliers data for current iteration.- Type Parameters:
T
- type of result to be estimated.- Parameters:
iterResult
- result to be tested on current iteration.threshold
- threshold to determine whether samples are inliers or not.inliers
- bitset indicating which samples are inliers. This is indicated in their original position before sorting.totalSamples
- total number of samples.listener
- listener to obtain residuals for samples.residuals
- array where residuals must be stored (if provided).- Returns:
- inliers data.
-
computeSortedQualityIndices
private static int[] computeSortedQualityIndices(double[] qualityScores) throws com.irurueta.sorting.SortingException Obtains indices of samples corresponding to samples ordered in descending quality scores.- Parameters:
qualityScores
- quality scores associated to each sample to be used to obtain indices to sort samples in descending order of quality values.- Returns:
- indices to sort samples in descending order of quality values.
- Throws:
com.irurueta.sorting.SortingException
- if sorting fails.
-
reverse
private static void reverse(int[] array) Reverses provided array.- Parameters:
array
- array to be reversed.
-
computeIterations
private static int computeIterations(double probInlier, int subsetSize, double confidence) Computes number of required iterations to achieve required confidence with current probability of inlier and sample subset size.- Parameters:
probInlier
- probability of inlier.subsetSize
- sample subset size.confidence
- required confidence of result.- Returns:
- number of required iterations.
-
imin
private static int imin(int subsetSize, int sampleSize, double beta) Non randomness states that i-m (where i is the cardinal of the set of inliers for a wrong model) follows the binomial distribution B(n,beta). For n big enough, B(n,beta) approximates to normal distribution N(mu, sigma^2) by the central limit theorem, with mu = n*beta and sigma = sqrt(n*beta*(1 - beta)). Psi, the probability that In_star out of n_star data points are by chance inliers to an arbitrary incorrect model, is set to 0.05 (5%, as in the original paper), and you must change the Chi2 value if you chose a different value for psi.- Parameters:
subsetSize
- sample subset size.sampleSize
- total number of samples.beta
- beta value.- Returns:
- i-m.
-