mpicbg.models.Tile Java Examples

The following examples show how to use mpicbg.models.Tile. 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: TileConfigurationStitching.java    From Stitching with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Estimate min/max/average displacement of all
 * {@link PointMatch PointMatches} in all {@link Tile Tiles}.
 */
@Override
protected void updateErrors()
{
	double cd = 0.0;
	minError = Double.MAX_VALUE;
	maxError = 0.0;
	for ( Tile< ? > t : tiles )
	{
		t.updateCost();
		double d = t.getDistance();
		if ( d < minError ) minError = d;
		
		// >= because if they are all 0.0, worstTile would be null
		if ( d >= maxError )
		{
			maxError = d;
			worstTile = t;
		}
		cd += d;
	}
	cd /= tiles.size();
	error = cd;

}
 
Example #2
Source File: Trakem2SolverClient.java    From render with GNU General Public License v2.0 6 votes vote down vote up
private Tile<InterpolatedAffineModel2D<AffineModel2D, B>> buildTileFromSpec(final TileSpec tileSpec) {

        final CoordinateTransformList<CoordinateTransform> transformList = tileSpec.getTransformList();
        final AffineModel2D lastTransform = (AffineModel2D)
                transformList.get(transformList.getList(null).size() - 1);
        final AffineModel2D lastTransformCopy = lastTransform.copy();

        final double sampleWidth = (tileSpec.getWidth() - 1.0) / (parameters.samplesPerDimension - 1.0);
        final double sampleHeight = (tileSpec.getHeight() - 1.0) / (parameters.samplesPerDimension - 1.0);

        final B regularizer = parameters.regularizerModelType.getInstance();

        try {
            ScriptUtil.fit(regularizer, lastTransformCopy, sampleWidth, sampleHeight, parameters.samplesPerDimension);
        } catch (final Throwable t) {
            throw new IllegalArgumentException(regularizer.getClass() + " model derivation failed for tile '" +
                                               tileSpec.getTileId() + "', cause: " + t.getMessage(),
                                               t);
        }

        return new Tile<>(new InterpolatedAffineModel2D<>(lastTransformCopy,
                                                          regularizer,
                                                          parameters.startLambda)); // note: lambda gets reset during optimization loops
    }
 
Example #3
Source File: MatchIntensities.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
final static protected < T extends Model< T > & Affine1D< T > > HashMap< Patch, ArrayList< Tile< T > > > generateCoefficientsTiles(
		final Collection< Patch > patches,
		final T template,
		final int nCoefficients )
{
	final HashMap< Patch, ArrayList< Tile< T > > > map = new HashMap< Patch, ArrayList< Tile< T > > >();
	for ( final Patch p : patches )
	{
		final ArrayList< Tile< T > > coefficientModels = new ArrayList< Tile< T > >();
		for ( int i = 0; i < nCoefficients; ++i )
			coefficientModels.add( new Tile< T >( template.copy() ) );

		map.put( p, coefficientModels );
	}
	return map;
}
 
Example #4
Source File: GlobalOpt.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
protected static void addPointMatches( final ArrayList< PointMatchGeneric< Detection > > correspondences, final Tile<?> tileA, final Tile<?> tileB )
{
	final ArrayList<PointMatch> pm = new ArrayList<PointMatch>();
	pm.addAll( correspondences );

	if ( correspondences.size() > 0 )
	{
		tileA.addMatches( pm );							
		tileB.addMatches( PointMatch.flip( pm ) );
		tileA.addConnectedTile( tileB );
		tileB.addConnectedTile( tileA );
	}
}
 
Example #5
Source File: GlobalOpt.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static void main( String[] args )
{
	// multiple keys can map to the same value
	final HashMap< ViewId, Tile< AffineModel3D > > map = new HashMap<ViewId, Tile<AffineModel3D>>();
	
	final AffineModel3D m1 = new AffineModel3D();
	final AffineModel3D m2 = new AffineModel3D();

	final Tile< AffineModel3D > tile1 = new Tile<AffineModel3D>( m1 );
	final Tile< AffineModel3D > tile2 = new Tile<AffineModel3D>( m2 );
	
	final ViewId v11 = new ViewId( 1, 1 );
	final ViewId v21 = new ViewId( 2, 1 );
	final ViewId v12 = new ViewId( 1, 2 );
	final ViewId v22 = new ViewId( 2, 2 );
	
	map.put( v11, tile1 );
	map.put( v21, tile2 );

	map.put( v12, tile1 );
	map.put( v22, tile2 );
	
	m1.set( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
	m2.set( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 );

	System.out.println( map.get( v11 ).getModel() );
	System.out.println( map.get( v21 ).getModel() );
	
	System.out.println( map.get( v12 ).getModel() );
	System.out.println( map.get( v22 ).getModel() );		
}
 
Example #6
Source File: DetectionRegistration.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public synchronized static <T extends AbstractDetection<T>> void addPointMatches( final ArrayList<PointMatchGeneric<T>> correspondences, final Tile<?> tileA, final Tile<?> tileB )
{
	final ArrayList<PointMatch> pm = new ArrayList<PointMatch>();
	pm.addAll( correspondences );

	if ( correspondences.size() > 0 )
	{
		tileA.addMatches( pm );							
		tileB.addMatches( PointMatch.flip( pm ) );
		tileA.addConnectedTile( tileB );
		tileB.addConnectedTile( tileA );
	}
}
 
Example #7
Source File: MatchIntensities.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public Matcher(
		final Rectangle roi,
		final ValuePair< Patch, Patch > patchPair,
		final HashMap< Patch, ArrayList< Tile< ? > > > coefficientsTiles,
		final PointMatchFilter filter,
		final double scale,
		final int numCoefficients )
{
	this.roi = roi;
	this.patchPair = patchPair;
	this.coefficientsTiles = coefficientsTiles;
	this.filter = filter;
	this.scale = scale;
	this.numCoefficients = numCoefficients;
}
 
Example #8
Source File: MatchIntensities.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final static protected void identityConnect( final Tile< ? > t1, final Tile< ? > t2, final double weight )
{
	final ArrayList< PointMatch > matches = new ArrayList< PointMatch >();
	matches.add( new PointMatch( new Point( new double[] { 0 } ), new Point( new double[] { 0 } ) ) );
	matches.add( new PointMatch( new Point( new double[] { 1 } ), new Point( new double[] { 1 } ) ) );
	t1.connect( t2, matches );
}
 
Example #9
Source File: Align.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final static protected void pairwiseAlign(
		final AbstractAffineTile2D< ? > tile,
		final Set< AbstractAffineTile2D< ? > > visited )
{
	visited.add( tile );
	for ( final Tile< ? > t : tile.getConnectedTiles() )
	{
		if ( visited.contains( t ) ) continue;
		pairwiseAlign( ( AbstractAffineTile2D< ? > )t, visited );
		// TODO Actually do it ...
	}
}
 
Example #10
Source File: AbstractAffineTile2D.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extract the common {@linkplain PointMatch PointMatches} of two tiles.
 *
 * @param other
 * @param commonMatches
 */
final public void commonPointMatches( final Tile< ? > other, final Collection< PointMatch > commonMatches )
{
	for ( final PointMatch pm : matches )
		for ( final PointMatch otherPm : other.getMatches() )
			if ( pm.getP1() == otherPm.getP2() )
			{
				commonMatches.add( pm );
				break;
			}
}
 
Example #11
Source File: Trakem2SolverClient.java    From render with GNU General Public License v2.0 4 votes vote down vote up
private void saveTargetStackTiles(final HashMap<String, Tile<InterpolatedAffineModel2D<AffineModel2D, B>>> idToTileMap)
        throws IOException {

    LOG.info("saveTargetStackTiles: entry");

    for (final ResolvedTileSpecCollection resolvedTiles : zToTileSpecsMap.values()) {

        final Set<String> tileIdsToRemove = new HashSet<>();

        for (final TileSpec tileSpec : resolvedTiles.getTileSpecs()) {

            final String tileId = tileSpec.getTileId();
            final Tile<InterpolatedAffineModel2D<AffineModel2D, B>> tile = idToTileMap.get(tileId);

            if (tile == null) {
                tileIdsToRemove.add(tileId);
            } else {
                resolvedTiles.addTransformSpecToTile(tileId,
                                                     getTransformSpec(tile.getModel()),
                                                     REPLACE_LAST);
            }

            if (parameters.mergedZ != null) {
                tileSpec.setZ(parameters.mergedZ);
            }

        }

        if (tileIdsToRemove.size() > 0) {
            LOG.info("removed {} unaligned tile specs from target collection", tileIdsToRemove.size());
            resolvedTiles.removeTileSpecs(tileIdsToRemove);
        }

        if (resolvedTiles.getTileCount() > 0) {
            targetDataClient.saveResolvedTiles(resolvedTiles, parameters.targetStack, null);
        } else {
            LOG.info("skipping tile spec save since no specs are left to save");
        }

    }

    LOG.info("saveTargetStackTiles: saved tiles for all split sections");

    if (parameters.completeTargetStack) {
        targetDataClient.setStackState(parameters.targetStack, StackMetaData.StackState.COMPLETE);
    }

    LOG.info("saveTargetStackTiles: exit");
}
 
Example #12
Source File: GlobalOptimizationSubset.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param model
 * @param type
 * @param spimData
 * @param channelsToProcess - just to annotate the registration
 * @param description
 * @return
 */
public < M extends Model< M > > boolean computeGlobalOpt(
		final M model,
		final GlobalOptimizationType type,
		final SpimData2 spimData,
		final List< ChannelProcess > channelsToProcess,
		final String description )
{
	final HashMap< ViewId, Tile< M > > tiles = GlobalOpt.compute( model, type, this, type.considerTimePointsAsUnit() );

	if ( tiles == null )
		return false;
	
	String channelList = "[";
	for ( final ChannelProcess c : channelsToProcess )
		channelList += c.getLabel() + " (c=" + c.getChannel().getName() + "), ";
	channelList = channelList.substring( 0, channelList.length() - 2 ) + "]";

	final AffineTransform3D mapBackModel;
	
	// TODO: Map back first tile as good as possible to original location???
	if ( type.getMapBackReferenceTile( this ) != null && type.getMapBackModel() != null )
		mapBackModel = computeMapBackModel( tiles, type, spimData );
	else
		mapBackModel = null;

	// update the view registrations
	for ( final ViewId viewId : this.getViews() )
	{
		final Tile< M > tile = tiles.get( viewId );
		
		// TODO: we assume that M is an Affine3D, which is not necessarily true
		final Affine3D< ? > tilemodel = (Affine3D< ? >)tile.getModel();
		final double[][] m = new double[ 3 ][ 4 ];
		tilemodel.toMatrix( m );
		
		final AffineTransform3D t = new AffineTransform3D();
		t.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] );
		
		if ( mapBackModel != null )
		{
			t.preConcatenate( mapBackModel );
			IOFunctions.println( "ViewId=" + viewId.getViewSetupId() + ": " + t );
		}
		
		Apply_Transformation.preConcatenateTransform( spimData, viewId, t, description + " on " + channelList );
	}

	return true;
}
 
Example #13
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 #14
Source File: TileConfigurationStitching.java    From Stitching with GNU General Public License v2.0 votes vote down vote up
final public Tile getWorstTile() {	return worstTile; }