Skip to content

Commit

Permalink
add minInlierRatio to ICP-RANSAC
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Mar 20, 2024
1 parent 84ebc64 commit 0d367e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public PairwiseResult< I > match( final List< I > listAIn, final List< I > listB
return result;
}

final ICP< I > icp = new ICP< I >( listA, listB, (float)ip.getMaxDistance(), ip.useRANSAC(), ip.getMaxEpsilonRANSAC(), ip.getMaxIterationsRANSAC() );
final ICP< I > icp = new ICP< I >( listA, listB, (float)ip.getMaxDistance(), ip.useRANSAC(), ip.getMinInlierRatio(), ip.getMaxEpsilonRANSAC(), ip.getMaxIterationsRANSAC() );

int i = 0;
double lastAvgError = 0;
Expand Down Expand Up @@ -175,7 +175,7 @@ public static void main( final String[] args ) throws Exception
IOFunctions.println( Util.printCoordinates( listA.get( i ).getL() ) + " >>> " + Util.printCoordinates( listB.get( i ).getL() ) + ", d=" + Point.distance( listA.get( i ), listB.get( i ) ) );
}

final ICP< InterestPoint > icp = new ICP< InterestPoint >( listA, listB, maxError, false, 0, 0 );
final ICP< InterestPoint > icp = new ICP< InterestPoint >( listA, listB, maxError, false, 0.0, 0, 0 );

// identity transform
TranslationModel3D model = new TranslationModel3D();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ public class IterativeClosestPointParameters
public static double defaultMaxEpsionRANSAC = maxDistance / 2.0;
public static int defaultNumIterationsRANSAC = 200;
public static int defaultMinNumPoints = 12;
public static double defaultMinInlierRatio = 0.1;

private double d;
private int maxIt;
private boolean useRANSAC;
private double maxEpsilonRANSAC;
private int maxIterationsRANSAC;
private int minNumPoints;
final private double d;
final private int maxIt;
final private boolean useRANSAC;
final private double maxEpsilonRANSAC;
final private double minInlierRatio;
final private int maxIterationsRANSAC;
final private int minNumPoints;

private Model< ? > model = null;

public IterativeClosestPointParameters(
final Model< ? > model,
final double maxDistance,
final int maxIterations,
final boolean useRANSAC,
final boolean useRANSAC,
final double minInlierRatio,
final double maxEpsilonRANSAC,
final int maxIterationsRANSAC,
final int minNumPoints )
Expand All @@ -56,6 +59,7 @@ public IterativeClosestPointParameters(
this.maxIt = maxIterations;
this.useRANSAC = useRANSAC;
this.maxEpsilonRANSAC = maxEpsilonRANSAC;
this.minInlierRatio = minInlierRatio;
this.maxIterationsRANSAC = maxIterationsRANSAC;
this.minNumPoints = minNumPoints;
}
Expand All @@ -64,16 +68,17 @@ public IterativeClosestPointParameters(
final Model< ? > model,
IterativeClosestPointParameters p )
{
this( model, p.getMaxDistance(), p.getMaxNumIterations(), p.useRANSAC(), p.getMaxEpsilonRANSAC(), p.getMaxIterationsRANSAC(), p.getMinNumPoints() );
this( model, p.getMaxDistance(), p.getMaxNumIterations(), p.useRANSAC(), p.getMinInlierRatio(), p.getMaxEpsilonRANSAC(), p.getMaxIterationsRANSAC(), p.getMinNumPoints() );
}

public IterativeClosestPointParameters( final Model< ? > model )
{
this( model, maxDistance, maxIterations, defaultUseRANSAC, defaultMaxEpsionRANSAC, defaultNumIterationsRANSAC, defaultMinNumPoints );
this( model, maxDistance, maxIterations, defaultUseRANSAC, defaultMinInlierRatio, defaultMaxEpsionRANSAC, defaultNumIterationsRANSAC, defaultMinNumPoints );
}

public Model< ? > getModel() { return model.copy(); }
public double getMaxDistance() { return d; }
public double getMinInlierRatio() { return minInlierRatio; }
public int getMaxNumIterations() { return maxIt; }
public boolean useRANSAC() { return useRANSAC; }
public double getMaxEpsilonRANSAC() { return maxEpsilonRANSAC; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ICP < P extends RealLocalizable >

final boolean useRANSAC;
final double maxEpsilonRANSAC;
final double minInlierRatio;
final int maxIterationsRANSAC;

double avgError, maxError;
Expand All @@ -67,14 +68,16 @@ public class ICP < P extends RealLocalizable >
* @param reference - the {@link List} of reference points
* @param pointMatchIdentifier - the {@link PointMatchIdentification} which defines how correspondences are established
* @param useRANSAC - use RANSAC during every iteration
* @param minInlierRatio - minInlierRatio for RANSAC
* @param maxEpsilonRANSAC - max error for RANSAC if used
* @param maxIterationsRANSAC - max iterations for RANSAC if used
*/
public ICP(
final List< P > target,
final List< P > reference,
final PointMatchIdentification< P > pointMatchIdentifier,
final boolean useRANSAC,
final boolean useRANSAC,
final double minInlierRatio,
final double maxEpsilonRANSAC,
final int maxIterationsRANSAC )
{
Expand Down Expand Up @@ -103,6 +106,7 @@ public ICP(
this.pointMatchIdentifier = pointMatchIdentifier;

this.useRANSAC = useRANSAC;
this.minInlierRatio = minInlierRatio;
this.maxEpsilonRANSAC = maxEpsilonRANSAC;
this.maxIterationsRANSAC = maxIterationsRANSAC;

Expand All @@ -118,6 +122,7 @@ public ICP(
* @param reference - the {@link List} of reference points
* @param distanceThreshold - the maximal distance of {@link SimplePointMatchIdentification}, so that the nearest neighbor of a point is still counted as a corresponding point
* @param useRANSAC - use RANSAC during every iteration
* @param minInlierRatio - minInlierRatio for RANSAC
* @param maxEpsilonRANSAC - max error for RANSAC if used
* @param maxIterationsRANSAC - max iterations for RANSAC if used
*/
Expand All @@ -126,10 +131,11 @@ public ICP(
final List< P > reference,
final double distanceThreshold,
final boolean useRANSAC,
final double minInlierRatio,
final double maxEpsilonRANSAC,
final int maxIterationsRANSAC )
{
this( target, reference, new SimplePointMatchIdentification< P >( distanceThreshold ), useRANSAC, maxEpsilonRANSAC, maxIterationsRANSAC );
this( target, reference, new SimplePointMatchIdentification< P >( distanceThreshold ), useRANSAC, minInlierRatio, maxEpsilonRANSAC, maxIterationsRANSAC );
}

/**
Expand All @@ -138,17 +144,19 @@ public ICP(
* @param target - the {@link List} of target points
* @param reference - the {@link List} of reference points
* @param useRANSAC - use RANSAC during every iteration
* @param minInlierRatio - minInlierRatio for RANSAC
* @param maxEpsilonRANSAC - max error for RANSAC if used
* @param maxIterationsRANSAC - max iterations for RANSAC if used
*/
public ICP(
final List< P > target,
final List< P > reference,
final boolean useRANSAC,
final boolean useRANSAC,
final double minInlierRatio,
final double maxEpsilonRANSAC,
final int maxIterationsRANSAC )
{
this( target, reference, new SimplePointMatchIdentification<P>(), useRANSAC, maxEpsilonRANSAC, maxIterationsRANSAC );
this( target, reference, new SimplePointMatchIdentification<P>(), useRANSAC, minInlierRatio, maxEpsilonRANSAC, maxIterationsRANSAC );
}

/**
Expand Down Expand Up @@ -176,7 +184,7 @@ public void runICPIteration( final Model<?> lastModel, final Model<?> newModel )

if ( useRANSAC )
{
newModel.filterRansac( candidates, matches, maxIterationsRANSAC, maxEpsilonRANSAC, 0.0f );
newModel.filterRansac( candidates, matches, maxIterationsRANSAC, maxEpsilonRANSAC, minInlierRatio );
//IOFunctions.println( "RANSAC: " + matches.size() + "/" + candidates.size() );
}
else
Expand Down

0 comments on commit 0d367e3

Please sign in to comment.