mpicbg.models.TranslationModel2D Java Examples

The following examples show how to use mpicbg.models.TranslationModel2D. 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: MovingLeastSquaresBuilder.java    From render with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Derives center point matches between the two specified tile lists using tileId to correlate the tiles.
 * The {@link #call} method can then be used to derive a moving least squares transform instance
 * from the point matches.
 *
 * @param  montageTiles  collection of tiles from a montage stack.
 * @param  alignTiles    collection of tiles from an align stack.
 * @param  alpha  transform alpha (optional, default is 1.0)
 */
public MovingLeastSquaresBuilder(final Collection<TileSpec> montageTiles,
                                 final Collection<TileSpec> alignTiles,
                                 final Double alpha) {

    readTileSpecs(montageTiles, alignTiles);

    if (w.length == 1) {
        modelClass = TranslationModel2D.class;
    } else if (w.length == 2) {
        modelClass = SimilarityModel2D.class;
    } else {
        modelClass = AffineModel2D.class;
    }

    this.alpha = alpha;
}
 
Example #2
Source File: GenericAffineTile2D.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings( "rawtypes" )
@Override
protected void initModel()
{
	final AffineTransform a = patch.getAffineTransform();
	if ( AffineModel2D.class.isInstance( model ) )
		( ( AffineModel2D )( Object )model ).set( a );
	else if ( SimilarityModel2D.class.isInstance( model ) )
		( ( SimilarityModel2D )( Object )model ).set( a.getScaleX(), a.getShearY(), a.getTranslateX(), a.getTranslateY() );
	else if ( RigidModel2D.class.isInstance( model ) )
		( ( RigidModel2D )( Object )model ).set( a.getScaleX(), a.getShearY(), a.getTranslateX(), a.getTranslateY() );
	else if ( TranslationModel2D.class.isInstance( model ) )
		( ( TranslationModel2D )( Object )model ).set( a.getTranslateX(), a.getTranslateY() );
	else if ( InterpolatedAffineModel2D.class.isInstance( model ) )
		( ( InterpolatedAffineModel2D )( Object )model ).set( a );
}
 
Example #3
Source File: ImagePlusTimePoint.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
public ImagePlusTimePoint( final ImagePlus imp, final int impId, final int timepoint, final Model model, final ImageCollectionElement element )
{
	super( model );
	this.imp = imp;
	this.impId = impId;
	this.timePoint = timepoint;
	this.element = element;
	
	if ( TranslationModel2D.class.isInstance( model ) )
		dimensionality = 2;
	else
		dimensionality = 3;
}
 
Example #4
Source File: HierarchicalStack.java    From render with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Converts the specified affine to a full scale version that can be used in an
     * {@link org.janelia.alignment.transform.AffineWarpFieldTransform}.
     *
     * @param  alignedLayerTransformModel  scaled aligned model to convert.
     * @param  alignedStackScale           scale of the aligned stack.
     * @param  fullScaleStackBounds        full scale bounds of the stack prior to alignment.
     *
     * @return full scale relative version of the specified model.
     */
    @JsonIgnore
    public static AffineModel2D getFullScaleRelativeModel(final AffineModel2D alignedLayerTransformModel,
                                                          final double alignedStackScale,
                                                          final Bounds fullScaleStackBounds) {

        final double invertedScale = 1.0 / alignedStackScale;
        final AffineModel2D invertedScaleModel = new AffineModel2D();
        invertedScaleModel.set(invertedScale, 0.0, 0.0, invertedScale, 0.0, 0.0);

        final AffineModel2D scaleModel = new AffineModel2D();
        scaleModel.set(alignedStackScale, 0.0, 0.0, alignedStackScale, 0.0, 0.0);

        final TranslationModel2D offsetModel = new TranslationModel2D();
        offsetModel.set(-fullScaleStackBounds.getMinX(), -fullScaleStackBounds.getMinY());

//        final double centerX = fullScaleStackBounds.getMinX() - (fullScaleStackBounds.getDeltaX() / 2.0);
//        final double centerY = fullScaleStackBounds.getMinY() - (fullScaleStackBounds.getDeltaY() / 2.0);
//        offsetModel.set(-centerX, -centerY);

        final AffineModel2D fullScaleRelativeModel = new AffineModel2D();
        fullScaleRelativeModel.concatenate(invertedScaleModel);
        fullScaleRelativeModel.concatenate(alignedLayerTransformModel);
        fullScaleRelativeModel.concatenate(scaleModel);
        fullScaleRelativeModel.concatenate(offsetModel);

        return fullScaleRelativeModel;
    }
 
Example #5
Source File: NonLinearTransformMode.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
private CoordinateTransform createCT() throws Exception
{
	final Collection< PointMatch > pm = new ArrayList<PointMatch>();
	for ( final Point p : points )
	{
		pm.add( new PointMatch( new Point( p.getL() ), new Point( p.getW() ) ) );
	}
	/*
	 * TODO replace this with the desired parameters of the transformation
	 */
	final MovingLeastSquaresTransform2 mlst = new MovingLeastSquaresTransform2();
	mlst.setAlpha( 1.0f );
	Class< ? extends AbstractAffineModel2D< ? > > c = AffineModel2D.class;
	switch (points.size()) {
		case 1:
			c = TranslationModel2D.class;
			break;
		case 2:
			c = SimilarityModel2D.class;
			break;
		default:
			break;
	}
	mlst.setModel( c );
	mlst.setMatches( pm );

	return mlst;
}
 
Example #6
Source File: TranslationTile2D.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public TranslationTile2D( final mpicbg.models.TranslationModel2D model, final Patch patch )
{
	super( model, patch );
}
 
Example #7
Source File: TranslationTile2D.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public TranslationTile2D( final Patch patch )
{
	this( new TranslationModel2D(), patch );
}
 
Example #8
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
static protected void extractSIFTPointsThreaded(
		final int index,
		final List< Feature >[] siftFeatures,
		final List< PointMatch >[] inliers,
		final AbstractAffineModel2D< ? >[] models )
{

	// save all matching candidates
	final List< PointMatch >[] candidates = new List[ siftFeatures.length - 1 ];

	final Thread[] threads = MultiThreading.newThreads();
	final AtomicInteger ai = new AtomicInteger( 0 ); // start at second
	// slice

	for ( int ithread = 0; ithread < threads.length; ++ithread )
	{
		threads[ ithread ] = new Thread()
		{
			@Override
               public void run()
			{
				setPriority( Thread.NORM_PRIORITY );

				for ( int j = ai.getAndIncrement(); j < candidates.length; j = ai.getAndIncrement() )
				{
					final int i = ( j < index ? j : j + 1 );
					candidates[ j ] = FloatArray2DSIFT.createMatches( siftFeatures[ index ], siftFeatures[ i ], 1.5f, null, Float.MAX_VALUE, 0.5f );
				}
			}
		};
	}

	MultiThreading.startAndJoin( threads );

	// get rid of the outliers and save the rigid transformations to match
	// the inliers

	final AtomicInteger ai2 = new AtomicInteger( 0 );
	for ( int ithread = 0; ithread < threads.length; ++ithread )
	{
		threads[ ithread ] = new Thread()
		{
			@Override
               public void run()
			{
				setPriority( Thread.NORM_PRIORITY );
				for ( int i = ai2.getAndIncrement(); i < candidates.length; i = ai2.getAndIncrement() )
				{

					final List< PointMatch > tmpInliers = new ArrayList< PointMatch >();
					// RigidModel2D m =
					// RigidModel2D.estimateBestModel(candidates.get(i),
					// tmpInliers, sp.min_epsilon, sp.max_epsilon,
					// sp.min_inlier_ratio);

					final AbstractAffineModel2D< ? > m;
					switch ( sp.expectedModelIndex )
					{
					case 0:
						m = new TranslationModel2D();
						break;
					case 1:
						m = new RigidModel2D();
						break;
					case 2:
						m = new SimilarityModel2D();
						break;
					case 3:
						m = new AffineModel2D();
						break;
					default:
						return;
					}

					boolean modelFound = false;
					try
					{
						modelFound = m.filterRansac( candidates[ i ], tmpInliers, 1000, sp.maxEpsilon, sp.minInlierRatio, 10 );
					}
					catch ( final NotEnoughDataPointsException e )
					{
						modelFound = false;
					}

					if ( modelFound )
						IJ.log( "Model found:\n  " + candidates[ i ].size() + " candidates\n  " + tmpInliers.size() + " inliers\n  " + String.format( "%.2f", m.getCost() ) + "px average displacement" );
					else
						IJ.log( "No Model found." );

					inliers[ index * ( sp.numberOfImages - 1 ) + i ] = tmpInliers;
					models[ index * ( sp.numberOfImages - 1 ) + i ] = m;
					// System.out.println("**** MODEL ADDED: " +
					// (index*(sp.numberOfImages-1)+i));
				}

			}
		};
	}
	MultiThreading.startAndJoin( threads );

}