mpicbg.models.ErrorStatistic Java Examples

The following examples show how to use mpicbg.models.ErrorStatistic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TileConfigurationSPIM.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Minimize the displacement of all {@link PointMatch Correspondence pairs}
 * of all {@link Tile Tiles}
 * 
 * @param maxAllowedError do not accept convergence if error is < max_error
 * @param maxIterations stop after that many iterations even if there was
 *   no minimum found
 * @param maxPlateauwidth convergence is reached if the average absolute
 *   slope in an interval of this size and half this size is smaller than
 *   0.0001 (in double accuracy).  This is assumed to prevent the algorithm
 *   from stopping at plateaus smaller than this value.
 * @param debugLevel defines if the Optimizer prints the output at the end of the process
 */
public void optimize(
		final double maxAllowedError,
		final int maxIterations,
		final int maxPlateauwidth,
		final int debugLevel ) throws NotEnoughDataPointsException, IllDefinedDataPointsException 
{
	final ErrorStatistic observer = new ErrorStatistic( maxPlateauwidth + 1 );
	
	int i = 0;
	
	boolean proceed = i < maxIterations;
	
	while ( proceed )
	{
		for ( final TileSPIM tile : tiles )
		{
			if ( fixedTiles.contains( tile ) ) continue;
			tile.update();
			tile.fitModel();
			tile.update();
		}
		update();
		observer.add( error );
		
		if ( i > maxPlateauwidth )
		{
			proceed = error > maxAllowedError;
			
			int d = maxPlateauwidth;
			while ( !proceed && d >= 1 )
			{
				try
				{
					proceed |= Math.abs( observer.getWideSlope( d ) ) > 0.0001;
				}
				catch ( Exception e ) { e.printStackTrace(); }
				d /= 2;
			}
		}
		
		proceed &= ++i < maxIterations;
	}
	
	if ( debugLevel <= ViewStructure.DEBUG_MAIN )
	{
		println( "Successfully optimized configuration of " + tiles.size() + " tiles after " + i + " iterations:" );
		println( "  average displacement: " + decimalFormat.format( error ) + "px" );
		println( "  minimal displacement: " + decimalFormat.format( minError ) + "px" );
		println( "  maximal displacement: " + decimalFormat.format( maxError ) + "px" );
	}
}
 
Example #2
Source File: BlockMatchPairCallable.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public BlockMatchResults call() throws Exception
    {
        final ArrayList< PointMatch > pm12 = new ArrayList< PointMatch >();
        final ArrayList< PointMatch > pm21 = new ArrayList< PointMatch >();

        System.out.println("BMC rev 0: " + pair.a + " " + pair.b);

        final Pair< FloatProcessor, FloatProcessor > pair1 = makeFlatImage( layer1, AlignmentUtils.filterPatches( layer1, filter ), box, param.layerScale );
        final Pair< FloatProcessor, FloatProcessor > pair2 = makeFlatImage( layer2, AlignmentUtils.filterPatches( layer2, filter ), box, param.layerScale );
        
        final FloatProcessor ip1 = pair1.a;
        final FloatProcessor ip1Mask = pair1.b;
        final FloatProcessor ip2 = pair2.a;
        final FloatProcessor ip2Mask = pair2.b;
        
        final AbstractModel< ? > localSmoothnessFilterModel =
                Util.createModel(param.localModelIndex);

        final int blockRadius =
                Math.max( 16, mpicbg.util.Util.roundPos( param.layerScale * param.blockRadius ) );

        /* scale pixel distances */
        final int searchRadius = ( int )Math.round( param.layerScale * param.searchRadius );
        final double localRegionSigma = param.layerScale * param.localRegionSigma;
        final double maxLocalEpsilon = param.layerScale * param.maxLocalEpsilon;

        if (!layer1Fixed)
        {


            BlockMatching.matchByMaximalPMCC(
                    ip1,
                    ip2,
                    ip1Mask,
                    ip2Mask,
                    1.0,
                    ((InvertibleCoordinateTransform) pair.c).createInverse(),
                    blockRadius,
                    blockRadius,
                    searchRadius,
                    searchRadius,
                    param.minR,
                    param.rodR,
                    param.maxCurvatureR,
                    v1,
                    pm12,
                    new ErrorStatistic(1));

            if ( Thread.interrupted() )
            {
                throw new InterruptedException("Block matching interrupted.");
            }

            if ( param.useLocalSmoothnessFilter )
            {
                localSmoothnessFilterModel.localSmoothnessFilter( pm12, pm12, localRegionSigma,
                        maxLocalEpsilon, param.maxLocalTrust );
            }
        }

        if (!layer2Fixed)
        {
            BlockMatching.matchByMaximalPMCC(
                    ip2,
                    ip1,
                    ip2Mask,
                    ip1Mask,
                    1.0f,
                    pair.c,
                    blockRadius,
                    blockRadius,
                    searchRadius,
                    searchRadius,
                    param.minR,
                    param.rodR,
                    param.maxCurvatureR,
                    v2,
                    pm21,
                    new ErrorStatistic( 1 ) );

            if ( Thread.interrupted() )
            {
                throw new InterruptedException("Block matching interrupted.");
            }

            if ( param.useLocalSmoothnessFilter )
            {
                localSmoothnessFilterModel.localSmoothnessFilter( pm21, pm21, localRegionSigma, maxLocalEpsilon, param.maxLocalTrust );
            }
        }

//        Utils.log( pair.a + " <> " + pair.b + " spring constant = " + springConstant );


        return new BlockMatchResults(v1, v2, pm12, pm21, layer1Fixed, layer2Fixed, pair);
    }