public SimilarityTile2D( final Patch patch ) { this( new SimilarityModel2D(), patch ); }
/** * Initialize the model such that the respective affine transform is: * * <pre> * s * cos(θ) -sin(θ) tx * sin(θ) s * cos(θ) ty * 0 0 1 * </pre> * * @param theta θ in radians * @param tx * @param ty */ final public void setScaleRotationTranslation( final double s, final double theta, final double tx, final double ty ) { set( s * Math.cos( theta ), s * Math.sin( theta ), tx, ty ); }
@Override final public double[] apply( final double[] l ) { assert l.length >= 2 : "2d similarity transformations can be applied to 2d points only."; final double[] transformed = l.clone(); applyInPlace( transformed ); return transformed; }
final SimilarityModel2D model = new SimilarityModel2D(); try model.fit( samples ); model.toArray( data ); return Math.sqrt( data[ 0 ] * data[ 0 ] + data[ 1 ] * data[ 1 ] );
final SimilarityModel2D toWorld = new SimilarityModel2D(); toWorld.set( 1.0 / magnification, 0, srcRect.x, srcRect.y ); final SimilarityModel2D toScreen = toWorld.createInverse(); toScreen.applyInPlace( l ); ctm.applyInverseInPlace( l ); toWorld.applyInPlace( l );
final SimilarityModel2D sTarget = new SimilarityModel2D(); sTarget.set( 1.0f / scale, 0, 0, 0 );
@Override protected void doPainterUpdate( final Rectangle r, final double m ) { try { final CoordinateTransform mlst = createCT(); final SimilarityModel2D toWorld = new SimilarityModel2D(); toWorld.set( 1.0 / m, 0, r.x - ScreenPatchRange.pad / m, r.y - ScreenPatchRange.pad / m ); final mpicbg.models.CoordinateTransformList< mpicbg.models.CoordinateTransform > ctl = new mpicbg.models.CoordinateTransformList< mpicbg.models.CoordinateTransform >(); ctl.add( toWorld ); ctl.add( mlst ); ctl.add( toWorld.createInverse() ); final CoordinateTransformMesh ctm = new CoordinateTransformMesh( ctl, 32, r.width * m + 2 * ScreenPatchRange.pad, r.height * m + 2 * ScreenPatchRange.pad ); final TransformMeshMappingWithMasks< CoordinateTransformMesh > mapping = new TransformMeshMappingWithMasks< CoordinateTransformMesh >( ctm ); final HashMap<Paintable, GroupingMode.ScreenPatchRange<?>> screenPatchRanges = this.screenPatchRanges; // keep a pointer to the current list for ( final GroupingMode.ScreenPatchRange spr : screenPatchRanges.values()) { if (screenPatchRanges != this.screenPatchRanges) { // List has been updated; restart painting // TODO should it call itself: doPainterUpdate( r, m ); break; } spr.update( mapping ); } } catch ( final NotEnoughDataPointsException e ) {} catch ( final NoninvertibleModelException e ) {} catch ( final IllDefinedDataPointsException e ) {} catch ( final Exception e ) { e.printStackTrace(); } }
@Override final protected void onReturn() { final double[] flatmatrix = new double[ 6 ]; myModel().toArray( flatmatrix ); IJ.log( "Matrix: " + Arrays.toString( flatmatrix ) ); } }
@Override final public double[] applyInverse( final double[] l ) { assert l.length >= 2 : "2d similarity transformations can be applied to 2d points only."; final double[] transformed = l.clone(); applyInverseInPlace( transformed ); return transformed; }
case 2: final SimilarityModel2D s = ( SimilarityModel2D )( Object )pair[ 1 ].getModel().createInverse(); s.concatenate( ( SimilarityModel2D )( Object )pair[ 0 ].getModel() ); m = s; break;
final SimilarityModel2D sTarget = new SimilarityModel2D(); sTarget.set( 1.0f / scale, 0, 0, 0 );
@Override final protected void onReturn() { final double[] flatmatrix = new double[ 6 ]; myModel().toArray( flatmatrix ); IJ.log( "Matrix: " + Arrays.toString( flatmatrix ) ); } }
@Override final public double[] applyInverse( final double[] l ) { assert l.length >= 2 : "2d similarity transformations can be applied to 2d points only."; final double[] transformed = l.clone(); applyInverseInPlace( transformed ); return transformed; }
@Override public SimilarityModel2D copy() { final SimilarityModel2D m = new SimilarityModel2D(); m.scos = scos; m.ssin = ssin; m.tx = tx; m.ty = ty; m.iscos = iscos; m.issin = issin; m.itx = itx; m.ity = ity; m.cost = cost; return m; }
break; case 2: params.model = new SimilarityModel2D(); break; case 3: break; case 2: params.model = new InterpolatedAffineModel2D( params.model, new SimilarityModel2D(), (float)params.lambda ); break; case 3: final SimilarityModel2D model = new SimilarityModel2D(); model.set( (float)( defaultScale*Math.cos( Math.toRadians( defaultDegrees1 ) ) ), (float)( defaultScale * Math.sin( Math.toRadians( defaultDegrees1 ) ) ), 0, 0 ); params.initialModel = model;
/** * Initialize the model such that the respective affine transform is: * * <pre> * s * cos(θ) -sin(θ) tx * sin(θ) s * cos(θ) ty * 0 0 1 * </pre> * * @param theta θ in radians * @param tx * @param ty */ final public void setScaleRotationTranslation( final double s, final double theta, final double tx, final double ty ) { set( s * Math.cos( theta ), s * Math.sin( theta ), tx, ty ); }
@Override final public double[] apply( final double[] l ) { assert l.length >= 2 : "2d similarity transformations can be applied to 2d points only."; final double[] transformed = l.clone(); applyInPlace( transformed ); return transformed; }
@Override public SimilarityModel2D copy() { final SimilarityModel2D m = new SimilarityModel2D(); m.scos = scos; m.ssin = ssin; m.tx = tx; m.ty = ty; m.iscos = iscos; m.issin = issin; m.itx = itx; m.ity = ity; m.cost = cost; return m; }
@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 ); }
/** * TODO Not yet tested */ //@Override @Override public SimilarityModel2D createInverse() { final SimilarityModel2D ict = new SimilarityModel2D(); ict.scos = iscos; ict.ssin = issin; ict.tx = itx; ict.ty = ity; ict.iscos = scos; ict.issin = ssin; ict.itx = tx; ict.ity = ty; ict.cost = cost; return ict; }