mpicbg.models.AbstractModel Java Examples

The following examples show how to use mpicbg.models.AbstractModel. 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: BlockMatchPairCallable.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public BlockMatchResults(final Collection<? extends Point> v1,
                         final Collection<? extends Point> v2,
                         final Collection<PointMatch> pm12,
                         final Collection<PointMatch> pm21,
                         final boolean layer1Fixed,
                         final boolean layer2Fixed,
                         final Triple<Integer, Integer, AbstractModel<?>> pair)
{
    this.v1 = v1;
    this.v2 = v2;
    this.pm12 = pm12;
    this.pm21 = pm21;
    this.layer1Fixed = layer1Fixed;
    this.layer2Fixed = layer2Fixed;
    this.pair = pair;
}
 
Example #2
Source File: BlockMatchPairCallable.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public BlockMatchPairCallable(final Triple<Integer, Integer, AbstractModel<?>> pair,
                              final List<Layer> layerRange,
                              final boolean layer1Fixed,
                              final boolean layer2Fixed,
                              final Filter<Patch> filter,
                              final ElasticLayerAlignment.Param param,
                              final Collection< ? extends Point > sourcePoints1,
                              final Collection< ? extends Point > sourcePoints2,
                              final Rectangle box)
{
    this.pair = pair;
    layer1 = layerRange.get(pair.a);
    layer2 = layerRange.get(pair.b);
    this.layer1Fixed = layer1Fixed;
    this.layer2Fixed = layer2Fixed;
    this.filter = filter;
    this.param = param;
    v1 = sourcePoints1;
    v2 = sourcePoints2;
    this.box = box;
}
 
Example #3
Source File: GlobalOptimizationSubset.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
protected < M extends Model< M > > AffineTransform3D computeMapBackModel( final HashMap< ViewId, Tile< M > > tiles, final GlobalOptimizationType type, final SpimData2 spimData )
{
	final AbstractModel< ? > mapBackModel = type.getMapBackModel();
	
	if ( mapBackModel.getMinNumMatches() > 4 )
	{
		IOFunctions.println( "Cannot map back using a model that needs more than 4 points: " + mapBackModel.getClass().getSimpleName() );

		return null;
	}
	else
	{
		IOFunctions.println( "Mapping back to reference frame using a " + mapBackModel.getClass().getSimpleName() );
		
		final ViewId referenceTile = type.getMapBackReferenceTile( this );
		final ViewDescription referenceTileViewDescription = spimData.getSequenceDescription().getViewDescription( referenceTile );
		final ViewSetup referenceTileSetup = referenceTileViewDescription.getViewSetup();
		Dimensions size = ViewSetupUtils.getSizeOrLoad( referenceTileSetup, referenceTileViewDescription.getTimePoint(), spimData.getSequenceDescription().getImgLoader() );
		long w = size.dimension( 0 );
		long h = size.dimension( 1 );

		final double[][] p = new double[][]{
				{ 0, 0, 0 },
				{ w, 0, 0 },
				{ 0, h, 0 },
				{ w, h, 0 } };

		// original coordinates == pa
		final double[][] pa = new double[ 4 ][ 3 ];
		
		// map coordinates to the actual input coordinates
		final ViewRegistration inputModel = spimData.getViewRegistrations().getViewRegistration( referenceTile );

		for ( int i = 0; i < p.length; ++i )
			inputModel.getModel().apply( p[ i ], pa[ i ] );
		
		final M outputModel = tiles.get( referenceTile ).getModel();
		
		// transformed coordinates == pb
		final double[][] pb = new double[ 4 ][ 3 ];

		for ( int i = 0; i < p.length; ++i )
			pb[ i ] = outputModel.apply( pa[ i ] );

		// compute the model that maps pb >> pa
		try
		{
			final ArrayList< PointMatch > pm = new ArrayList< PointMatch >();
			
			for ( int i = 0; i < p.length; ++i )
				pm.add( new PointMatch( new Point( pb[ i ] ), new Point( pa[ i ] ) ) );
			
			mapBackModel.fit( pm );
		} catch ( Exception e )
		{
			IOFunctions.println( "Could not compute model for mapping back: " + e );
			e.printStackTrace();
			return null;
		}

		final AffineTransform3D mapBack = new AffineTransform3D();
		final double[][] m = new double[ 3 ][ 4 ];
		((Affine3D<?>)mapBackModel).toMatrix( m );
		
		mapBack.set( m[0][0], m[0][1], m[0][2], + m[0][3],
					m[1][0], m[1][1], m[1][2], m[1][3], 
					m[2][0], m[2][1], m[2][2], m[2][3] );

		IOFunctions.println( "Model for mapping back: " + mapBack + "\n" );

		return mapBack;
	}
}
 
Example #4
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);
    }
 
Example #5
Source File: GlobalOptimizationType.java    From SPIM_Registration with GNU General Public License v2.0 2 votes vote down vote up
/**
 * The transformation model used to map back to the reference frame (can be null)
 * 
 * @return - a new instance of the model
 */
public AbstractModel<?> getMapBackModel() { return mapBackModel; }
 
Example #6
Source File: GlobalOptimizationType.java    From SPIM_Registration with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param model - The transformation model used to map back to the reference frame (can be null)
 */
public void setMapBackModel( final AbstractModel<?> model ) { this.mapBackModel = model; }