mpicbg.models.AffineModel3D Java Examples

The following examples show how to use mpicbg.models.AffineModel3D. 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: AutomaticAngleSetup.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static void main( String[] args )
{
	final SPIMConfiguration config = IOFunctions.initSPIMProcessing();
	
	//
	// load the files
	//
	final ViewStructure viewStructure = ViewStructure.initViewStructure( config, 0, new AffineModel3D(), "ViewStructure Timepoint " + 0, config.debugLevelInt );						

	for ( final ViewDataBeads view : viewStructure.getViews() )
	{
		view.loadDimensions();
		view.loadSegmentation();
		view.loadRegistration();
	}
	
	// This scaling is wrong here!
	// BeadRegistration.concatenateAxialScaling( viewStructure.getViews(), viewStructure.getDebugLevel() );		
	
	new AutomaticAngleSetup( viewStructure );
}
 
Example #2
Source File: Compare.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Transfer vs via a moving least squares transform by matching source named points into equally named target named points.
 *  If no points in common, returns null. */
static public List<VectorString3D> transferVectorStrings(final List<VectorString3D> vs, final Map<String,Tuple3d> source, final Map<String,Tuple3d> target) throws Exception {
	if (null == source || null == target) return null;
	final List<Tuple3d> so = new ArrayList<Tuple3d>();
	final List<Tuple3d> ta = new ArrayList<Tuple3d>();
	for (final Map.Entry<String,Tuple3d> e : target.entrySet()) {
		final Tuple3d point = source.get(e.getKey());
		if (null != point) {
			so.add(point);
			ta.add(e.getValue());
		}
	}
	if (0 == so.size()) {
		Utils.log2("No points in common!");
		return null;
	}
	Utils.log2("Found points in common: " + so.size());
	return transferVectorStrings(vs, so, ta, AffineModel3D.class);
}
 
Example #3
Source File: TransformUtils.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static Matrix4d getMatrix4d( final AffineModel3D model )
{
	final Matrix4d matrix = new Matrix4d();

	final double[] m = new double[ 12 ];
	model.getMatrix( m );

	matrix.m00 = m[ 0 ];
	matrix.m01 = m[ 1 ];
	matrix.m02 = m[ 2 ];
	matrix.m03 = m[ 3 ];
	matrix.m10 = m[ 4 ];
	matrix.m11 = m[ 5 ];
	matrix.m12 = m[ 6 ];
	matrix.m13 = m[ 7 ];
	matrix.m20 = m[ 8 ];
	matrix.m21 = m[ 9 ];
	matrix.m22 = m[ 10 ];
	matrix.m23 = m[ 11 ];
	matrix.m30 = 0;
	matrix.m31 = 0;
	matrix.m32 = 0;
	matrix.m33 = 0;

	return matrix;
}
 
Example #4
Source File: AutomaticAngleSetup.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public AutomaticAngleSetup( final ViewStructure viewStructure )
{		
	final ArrayList<ViewDataBeads>views = viewStructure.getViews();
	
	final ViewDataBeads viewA = views.get( 0 ); 
	final ViewDataBeads viewB = views.get( 1 );
	
	IOFunctions.println("Using view " + viewA.getName() + " and " + viewB.getName() + " for automatic angle setup." );
	
	final Vector3d rotationAxis = extractRotationAxis( (AffineModel3D)viewA.getTile().getModel(), (AffineModel3D)viewB.getTile().getModel() );
	//final float rotationAngle = extractRotationAngle( viewA.getTile().getModel(), viewB.getTile().getModel(), rotationAxis );
	//IOFunctions.println( "rotation axis: " + rotationAxis + ", angle: " + rotationAngle );
			
	IOFunctions.println( "rotation axis: " + rotationAxis );		
	rotationAxis.normalize();		
	IOFunctions.println( "rotation axis normed: " + rotationAxis );
	final Vector3d xAxis = new Vector3d( new double[] { 1, 0, 0 } );
			
	IOFunctions.println( "Difference to xAxis: " + distance( rotationAxis, xAxis ) );
	//testRotationAxis();
	//getCommonAreaPerpendicularViews( viewA, viewB );
}
 
Example #5
Source File: VisualizeBeads.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public VisualizeBeads( SPIMConfiguration config )
{
	this.config = config;

	viewStructure = ViewStructure.initViewStructure( config, 0, new AffineModel3D(), "ViewStructure Timepoint " + 0, config.debugLevelInt );						
	views = viewStructure.getViews();

	for ( ViewDataBeads view : viewStructure.getViews() )
	{
		view.loadDimensions();
		view.loadSegmentation();
		view.loadRegistration();
	}

	writeSketchTikZ("src/templates/beadimage-1.sk", "src/templates/allViewsWorm.sk");
}
 
Example #6
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public ExtractPSF( final SPIMConfiguration config )
{
	//
	// load the files
	//
	final ViewStructure viewStructure = ViewStructure.initViewStructure( config, 0, new AffineModel3D(), "ViewStructure Timepoint 0", config.debugLevelInt );						

	for ( ViewDataBeads view : viewStructure.getViews() )
	{
		view.loadDimensions();
		view.loadSegmentation();
		view.loadRegistration();

		BeadRegistration.concatenateAxialScaling( view, ViewStructure.DEBUG_MAIN );
	}
	
	this.viewStructure = viewStructure;
	this.pointSpreadFunctions = new ArrayList<Image<FloatType>>();
	this.originalPSFs = new ArrayList<Image<FloatType>>();
	this.conf = config;
	
	setPSFSize( Multi_View_Deconvolution.psfSize, Multi_View_Deconvolution.isotropic, Multi_View_Deconvolution.psfSize3d );
}
 
Example #7
Source File: SPIMConfiguration.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public AbstractAffineModel3D getModel()
  {
if ( transformationModel.equals( "Translation" ) )
	return new TranslationModel3D();
else if ( transformationModel.equals( "Rigid" ) )
	return new RigidModel3D();
else
	return new AffineModel3D();
  }
 
Example #8
Source File: TransformUtils.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static AffineModel3D getAffineModel3D( Transform3D transform )
{
	final double[] m = new double[16];
	transform.get( m );

	AffineModel3D model = new AffineModel3D();
	model.set( m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11] );

	return model;
}
 
Example #9
Source File: TransformUtils.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static void main( String[] args )
{
	AffineModel3D m = new AffineModel3D();
	m.set( 0.87912226f, 0.425894f, 0.21391234f, -169.3024f, -0.47269103f, 0.836501f, 0.2771809f, 42.627777f, -0.0608882f, -0.34479034f, 0.93670285f, 246.59639f );
	Transform3D t = TransformUtils.getTransform3D1( m );
	Vector3d s = new Vector3d();
	t.getScale( s );
	System.out.println( s );
}
 
Example #10
Source File: TestPointDescriptor.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
protected void applyTransform( final ArrayList<Point> points )
{
       final Transform3D trans = new Transform3D();
       trans.rotX( Math.toRadians( 30 ) );
       
       final AffineModel3D model = TransformUtils.getAffineModel3D( trans );
       
       for ( final Point p : points )
       {
       	model.apply( p.getL() );
       	model.apply( p.getW() );
       }        			
}
 
Example #11
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 #12
Source File: AutomaticAngleSetup.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static double extractRotationAngle( final AffineModel3D modelA, final AffineModel3D modelB, final Vector3d rotationAxis )
{
	final Transform3D transformA = TransformUtils.getTransform3D( modelA );
	final Transform3D transformB = TransformUtils.getTransform3D( modelB );

	// reset translational components
	transformA.setTranslation( new Vector3d() );
	transformB.setTranslation( new Vector3d() );
	
	final Transform3D connectingTransform = new Transform3D();
	final Transform3D tmp = new Transform3D();
	
	final Matrix3d matrix1 = new Matrix3d();
	final Matrix3d matrix2 = new Matrix3d();
	
	transformB.get( matrix2 );
	
	double minError = Float.MAX_VALUE;
	double minAngle = -1;
	
	for ( double angle = 0f; angle < 360.0f; angle += 1f )
	{
		connectingTransform.setIdentity();
		connectingTransform.setRotation( new AxisAngle4d( rotationAxis, Math.toRadians( angle ) ) );
	
		tmp.set( transformA );
		tmp.mul( connectingTransform );
		
		tmp.get( matrix1 );
		
		matrix1.sub( matrix2 );
		
		final double diff = matrix1.m00 * matrix1.m00 + matrix1.m01 * matrix1.m01 + matrix1.m02 * matrix1.m02 +
						   matrix1.m10 * matrix1.m10 + matrix1.m11 * matrix1.m11 + matrix1.m12 * matrix1.m12 +
						   matrix1.m20 * matrix1.m20 + matrix1.m21 * matrix1.m21 + matrix1.m22 * matrix1.m22;

		IOFunctions.println( angle + " " + diff );
		
		if ( diff < minError )
		{
			minError = diff;
			minAngle = angle;
		}
	}
	
	return minAngle;
}
 
Example #13
Source File: AutomaticAngleSetup.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Computes the rotation axis between two affine matrices, assuming that the first affine transform is the identity transform E. 
 * The rotation axis is just a relative ratio between x,y and z, so x is set to 1.
 * @param model - the second affine transformation 
 * @return - the Vector containing the rotation axis
 */
public static Vector3d extractRotationAxis( final AffineModel3D model )
{
	final double[] matrix = model.getMatrix( null );
			
	final double m00 = matrix[ 0 ];
	final double m01 = matrix[ 1 ];
	final double m02 = matrix[ 2 ];
	final double m10 = matrix[ 4 ];
	final double m11 = matrix[ 5 ];
	final double m12 = matrix[ 6 ];
	final double m20 = matrix[ 8 ];
	final double m21 = matrix[ 9 ];
	final double m22 = matrix[ 10 ];
	
	final Vector3d rotationAxis = new Vector3d( 1, 0, 0 );
	
	final double x = rotationAxis.x;		
	rotationAxis.y = ( ( 1 - m00 ) * ( 1 - m22 ) * x - m20 * m02 * x ) / ( m01 * ( 1 - m22 ) + m21 * m02 );
	rotationAxis.z = ( ( 1 - m00 ) * ( 1 - m11 ) * x - m10 * m01 * x ) / ( m02 * ( 1 - m11 ) + m12 * m01 );
	
	return rotationAxis;
	
	/*
	IOFunctions.println( modelA );
	IOFunctions.println( modelB );
	
	final float[] v1 = new float[ 3 ];
	v1[ 0 ] = -1;
	v1[ 1 ] = 0;
	v1[ 2 ] = 0;
	
	final float[] v2 = v1.clone();
	
	modelA.applyInPlace( v1 );
	modelB.applyInPlace( v2 );
	
	float sum = 0;
	for ( int j = 0; j < 3; ++j )
		sum += (v1[ j ] - v2[ j ]) * (v1[ j ] - v2[ j ]);
		
	IOFunctions.println( sum );
	*/
}
 
Example #14
Source File: AutomaticAngleSetup.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Computes the rotation axis between two affine matrices. 
 * The rotation axis is just a relative ratio between x,y and z, so x is set to 1.
 * @param modelA - the first affine transformation 
 * @param modelB - the second affine transformation 
 * @return - the Vector containing the rotation axis
 */
public static Vector3d extractRotationAxis( final AffineModel3D modelA, final AffineModel3D modelB )
{
	final double[] matrixA = modelA.getMatrix( null );
	final double[] matrixB = modelB.getMatrix( null );
			
	final double m00 = matrixA[ 0 ];
	final double m01 = matrixA[ 1 ];
	final double m02 = matrixA[ 2 ];
	final double m10 = matrixA[ 4 ];
	final double m11 = matrixA[ 5 ];
	final double m12 = matrixA[ 6 ];
	final double m20 = matrixA[ 8 ];
	final double m21 = matrixA[ 9 ];
	final double m22 = matrixA[ 10 ];

	final double n00 = matrixB[ 0 ];
	final double n01 = matrixB[ 1 ];
	final double n02 = matrixB[ 2 ];
	final double n10 = matrixB[ 4 ];
	final double n11 = matrixB[ 5 ];
	final double n12 = matrixB[ 6 ];
	final double n20 = matrixB[ 8 ];
	final double n21 = matrixB[ 9 ];
	final double n22 = matrixB[ 10 ];
	
	final Vector3d rotationAxis = new Vector3d( 1, 0, 0 );
	
	final double x = rotationAxis.x;		
	rotationAxis.y = ( ( m00 - n00 ) * ( m22 - n22 ) * x - ( n20 - m20 ) * ( n02 - m02 ) * x ) / 
					 ( ( n01 - m01 ) * ( m22 - n22 ) + ( n21 - m21 ) * ( n02 - m02 ) );
	rotationAxis.z = ( ( m00 - n00 ) * ( m11 - n11 ) * x - ( n10 - m10 ) * ( n01 - m01 ) * x ) / 
					 ( ( n02 - m02 ) * ( m11 - n11 ) + ( n12 - m12 ) * ( n01 - m01 ) );
	
	return rotationAxis;
	
	/*
	IOFunctions.println( modelA );
	IOFunctions.println( modelB );
	
	final float[] v1 = new float[ 3 ];
	v1[ 0 ] = -1;
	v1[ 1 ] = 0;
	v1[ 2 ] = 0;
	
	final float[] v2 = v1.clone();
	
	modelA.applyInPlace( v1 );
	modelB.applyInPlace( v2 );
	
	float sum = 0;
	for ( int j = 0; j < 3; ++j )
		sum += (v1[ j ] - v2[ j ]) * (v1[ j ] - v2[ j ]);
		
	IOFunctions.println( sum );
	*/
}
 
Example #15
Source File: TransformTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static AffineTransform3D mapBackTransform(AffineGet to, AffineGet from)
{
	final double[][] p = new double[][]{
		{ 0, 0, 0 },
		{ 1, 0, 0 },
		{ 0, 1, 0 },
		{ 1, 1, 0 },
		{ 0, 0, 1 },
		{ 1, 0, 1 },
		{ 0, 1, 1 },
		{ 1, 1, 1 }};

	final double[][] pa = new double[8][3];
	final double[][] pb = new double[8][3];
	
	for ( int i = 0; i < p.length; ++i )
		to.apply( p[ i ], pa[ i ] );
	
	for ( int i = 0; i < p.length; ++i )
		from.apply( p[ i ], pb[ i ] );
	
	// compute the model that maps pb >> pa
	AffineModel3D mapBackModel = new AffineModel3D();
	
	try
	{
		final ArrayList< PointMatch > pm = new ArrayList< PointMatch >();

		for ( int i = 0; i < p.length; ++i )
			pm.add( new PointMatch( new mpicbg.models.Point( pb[i] ), new mpicbg.models.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] );

	return mapBack;
	
}
 
Example #16
Source File: IOFunctions.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static void reWriteRegistrationFile( final File file, final AffineModel3D newModel, final AffineModel3D oldModel, final AffineModel3D preConcatenated )
{
	try 
	{
		// read the old file
		final ArrayList< String > content = new ArrayList< String >();
		final BufferedReader in = TextFileAccess.openFileRead( file );
		
		while ( in.ready() )
			content.add( in.readLine().trim() );

		in.close();
		
		// over-write the old file
		final PrintWriter out = TextFileAccess.openFileWrite( file );
		
		// get the model parameters
		final double[] matrixNew = newModel.getMatrix( null );
		
		for ( final String entry : content )
		{
			if (entry.startsWith("m00:"))
				out.println( "m00: " + matrixNew[ 0 ] );
			else if (entry.startsWith("m01:"))
				out.println( "m01: " + matrixNew[ 1 ] );
			else if (entry.startsWith("m02:"))
				out.println( "m02: " + matrixNew[ 2 ] );
			else if (entry.startsWith("m03:"))
				out.println( "m03: " + matrixNew[ 3 ] );
			else if (entry.startsWith("m10:"))
				out.println( "m10: " + matrixNew[ 4 ] );
			else if (entry.startsWith("m11:"))
				out.println( "m11: " + matrixNew[ 5 ] );
			else if (entry.startsWith("m12:"))
				out.println( "m12: " + matrixNew[ 6 ] );
			else if (entry.startsWith("m13:"))
				out.println( "m13: " + matrixNew[ 7 ] );
			else if (entry.startsWith("m20:"))
				out.println( "m20: " + matrixNew[ 8 ] );
			else if (entry.startsWith("m21:"))
				out.println( "m21: " + matrixNew[ 9 ] );
			else if (entry.startsWith("m22:"))
				out.println( "m22: " + matrixNew[ 10 ] );
			else if (entry.startsWith("m23:"))
				out.println( "m23: " + matrixNew[ 11 ] );
			else if (entry.startsWith("model:"))
				out.println( "model: AffineModel3D" );
			else
				out.println( entry );
		}
		
		// save the old models, just in case
		final double[] matrixOld = oldModel.getMatrix( null );
		final double[] matrixConcat = preConcatenated.getMatrix( null );

		out.println();
		out.println( "Previous model: " + Util.printCoordinates( matrixOld ) );
		out.println( "Pre-concatenated model: " + Util.printCoordinates( matrixConcat ) );
		
		out.close();
	} 
	catch (IOException e) 
	{
		IJ.log( "Cannot find file: " + file.getAbsolutePath() + ": " + e );
		// TODO Auto-generated catch block
		e.printStackTrace();
		return;
	}	
}
 
Example #17
Source File: IOFunctions.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static AffineModel3D getModelFromFile( final File file )
{
	final AffineModel3D model = new AffineModel3D();
			
	try 
	{
		final BufferedReader in = TextFileAccess.openFileRead( file );
		
		// get 12 entry double array
		final double m[] = new double[ 12 ];
		
		// the default if nothing is written
		String savedModel = "AffineModel3D";

		while ( in.ready() )
		{
			String entry = in.readLine().trim();
			
			if (entry.startsWith("m00:"))
				m[ 0 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m01:"))
				m[ 1 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m02:"))
				m[ 2 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m03:"))
				m[ 3 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m10:"))
				m[ 4 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m11:"))
				m[ 5 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m12:"))
				m[ 6 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m13:"))
				m[ 7 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m20:"))
				m[ 8 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m21:"))
				m[ 9 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m22:"))
				m[ 10 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("m23:"))
				m[ 11 ] = Double.parseDouble(entry.substring(5, entry.length()));
			else if (entry.startsWith("model:"))
				savedModel = entry.substring(7, entry.length()).trim();
		}

		in.close();
		
		if ( !savedModel.equals("AffineModel3D") )
			IOFunctions.println( "Warning: Loading a '" + savedModel + "' as AffineModel3D!" );
			
		model.set( m[ 0 ], m[ 1 ], m[ 2 ], m[ 3 ], m[ 4 ], m[ 5 ], m[ 6 ], m[ 7 ], m[ 8 ], m[ 9 ], m[ 10 ], m[ 11 ] );
		
	} 
	catch (IOException e) 
	{
		IJ.log( "Cannot find file: " + file.getAbsolutePath() + ": " + e );
		// TODO Auto-generated catch block
		e.printStackTrace();
		return null;
	}
	
	return model;
}
 
Example #18
Source File: TimeLapseDisplay.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static ArrayList< RegistrationStatistics > loadData( SPIMConfiguration conf )
{
	ArrayList< RegistrationStatistics > data = new ArrayList< RegistrationStatistics >();

	for (int timePointIndex = 0; timePointIndex < conf.file.length; timePointIndex++)
	{
		final ViewStructure timepoint = ViewStructure.initViewStructure( conf, timePointIndex, new AffineModel3D(), "ViewStructure Timepoint " + conf.timepoints[timePointIndex], ViewStructure.DEBUG_ERRORONLY );

		timepoint.loadDimensions();
		timepoint.loadSegmentations();
		timepoint.loadRegistrations();

		//System.out.println( timepoint );
		double minError = timepoint.getGlobalErrorStatistics().getMinAlignmentError();
		double avgError = timepoint.getGlobalErrorStatistics().getAverageAlignmentError();
		double maxError = timepoint.getGlobalErrorStatistics().getMaxAlignmentError();

		double minRatio = 1;
		double maxRatio = 0;
		double avgRatio = 0;
		int numViews = 0;
		ViewDataBeads worstView = null;

		for ( final ViewDataBeads view : timepoint.getViews() )
		{
			if ( view.getUseForRegistration() )
			{
				final ArrayList<Bead> beadList = view.getBeadStructure().getBeadList();

				int candidates = 0;
				int correspondences = 0;

				for ( final Bead bead : beadList )
				{
					candidates += bead.getDescriptorCorrespondence().size();
					correspondences += bead.getRANSACCorrespondence().size();
				}

				if ( candidates > 0 )
				{
					final double ratio = (double)correspondences / (double)candidates;

					if ( ratio < minRatio )
					{
						minRatio = ratio;
						worstView = view;
					}

					if ( ratio > maxRatio )
						maxRatio = ratio;

					avgRatio += ratio;
				}
				else
				{
					minRatio = 0;
				}
				numViews++;
			}
		}

		avgRatio /= numViews;

		System.out.println("data.add( new TimepointData( "+timepoint.getTimePoint()+", "+minError+", "+avgError+", "+maxError+", "+minRatio+", "+avgRatio+", "+maxRatio+" ) );");
		data.add( new RegistrationStatistics( timepoint.getTimePoint(), minError, avgError, maxError, minRatio, avgRatio, maxRatio, new File( worstView.getFileName() ) ) );

		//ImageJFunctions.show( worstView.getImage() );
	}

	return data;
}
 
Example #19
Source File: Stack.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
private void update()
	{
		boundsMin[ 0 ] = 0;
		boundsMin[ 1 ] = 0;
		boundsMin[ 2 ] = 0;

		boundsMax[ 0 ] = width;
		boundsMax[ 1 ] = height;
		boundsMax[ 2 ] = depth;

		if ( ict == null )
		{
//			Utils.log2( "ict is null" );
			return;
		}
		else if ( Boundable.class.isInstance( ict ) )
		{
//			Utils.log2( ict + " is a boundable" );
			( ( Boundable )ict ).estimateBounds( boundsMin, boundsMax );
//			Utils.log2( ict + "its bounds are (" + boundsMin[ 0 ] + ", " + boundsMin[ 1 ] + ", " + boundsMin[ 2 ] + ") -> (" + boundsMax[ 0 ] + ", " + boundsMax[ 1 ] + ", " + boundsMax[ 2 ] + ")" );
		}
		else
		{
			Utils.log2( ict + " is not a boundable" );
			final ArrayList< Layer > layers = layer_set.getLayers();
			boundsMax[ 0 ] = layer_set.width;
			boundsMax[ 1 ] = layer_set.height;
			boundsMax[ 2 ] = ( layers.get( layers.size() - 1 ).getZ() - layers.get( 0 ).getZ() );
		}

		if ( ict != null )
		{
			if ( AffineModel3D.class.isInstance( ict ) )
			{
				final double[] m = ( ( AffineModel3D )ict ).getMatrix( null );

				final double dxs = m[ 0 ] * m[ 0 ] + m[ 4 ] * m[ 4 ];
				final double dys = m[ 1 ] * m[ 1 ] + m[ 5 ] * m[ 5 ];
				final double dzs = m[ 2 ] * m[ 2 ] + m[ 6 ] * m[ 6 ];

				ictScale = Math.sqrt( Math.max( dxs, Math.max( dys, dzs ) ) );
			}
		}
	}