Java Code Examples for mpicbg.models.CoordinateTransform#applyInPlace()

The following examples show how to use mpicbg.models.CoordinateTransform#applyInPlace() . 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: ScriptUtil.java    From render with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Applies two transforms to a set of sampled locations and calculates the distance between the results
 * for each location.  The maximum distance between all sample locations is returned.
 *
 * Stolen from
 *
 * <a href="https://github.com/axtimwalde/fiji-scripts/blob/master/TrakEM2/visualize-ct-difference.bsh#L56-L72">
 *     https://github.com/axtimwalde/fiji-scripts/blob/master/TrakEM2/visualize-ct-difference.bsh#L56-L72
 * </a>.
 *
 * @param  coordinateTransform1  first transform to apply to all sampled points.
 * @param  coordinateTransform2  comparison transform to apply to all sampled points.
 * @param  sampleWidth           width of each sample.
 * @param  sampleHeight          height of each sample.
 * @param  samplesPerDimension   number of samples to take in each dimension.
 *
 * @return maximum delta between transformations of all sample locations.
 */
public static double calculateMaxDelta(final CoordinateTransform coordinateTransform1,
                                       final CoordinateTransform coordinateTransform2,
                                       final double sampleWidth,
                                       final double sampleHeight,
                                       final int samplesPerDimension) {

    double maxDelta = 0.0;

    for (int y = 0; y < samplesPerDimension; ++y) {
        final double sampleY = y * sampleHeight;
        for (int x = 0; x < samplesPerDimension; ++x) {
            final double sampleX = x * sampleWidth;
            final double[] l1 = new double[]{sampleX, sampleY};
            final double[] l2 = new double[]{sampleX, sampleY};
            coordinateTransform1.applyInPlace(l1);
            coordinateTransform2.applyInPlace(l2);
            final double dx = l1[0] - l2[0];
            final double dy = l1[1] - l2[1];
            final double d = Math.sqrt((dx * dx) + (dy * dy));
            maxDelta = Math.max(maxDelta, d);
        }
    }

    return maxDelta;
}
 
Example 2
Source File: RenderTransformMesh.java    From render with GNU General Public License v2.0 5 votes vote down vote up
final static protected void addPointMatch(final int i, final double[][] pq, final double[] point, final CoordinateTransform t, final double x, final double y) {
    point[0] = x;
    point[1] = y;
    t.applyInPlace(point);

    pq[0][i] = x;
    pq[1][i] = y;
    pq[2][i] = point[0];
    pq[3][i] = point[1];
}
 
Example 3
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
private static float[][] getMinMaxDim( final int[] dimensions, final CoordinateTransform transform )
{
	final int numDimensions = dimensions.length;
	
	final double[] tmp = new double[ numDimensions ];
	final float[][] minMaxDim = new float[ numDimensions ][ 2 ];
	
	for ( int d = 0; d < numDimensions; ++d )
	{
		minMaxDim[ d ][ 0 ] = Float.MAX_VALUE;
		minMaxDim[ d ][ 1 ] = -Float.MAX_VALUE;
	}
	
	// recursively get all corner points of the image, assuming they will still be the extremum points
	// in the transformed image
	final boolean[][] positions = new boolean[ Util.pow( 2, numDimensions ) ][ numDimensions ];
	Util.setCoordinateRecursive( numDimensions - 1, numDimensions, new int[ numDimensions ], positions );
	
	// get the min and max location for each dimension independently  
	for ( int i = 0; i < positions.length; ++i )
	{
		for ( int d = 0; d < numDimensions; ++d )
		{
			if ( positions[ i ][ d ])
				tmp[ d ] = dimensions[ d ] - 1;
			else
				tmp[ d ] = 0;
		}
		
		transform.applyInPlace( tmp );
		
		for ( int d = 0; d < numDimensions; ++d )
		{				
			if ( tmp[ d ] < minMaxDim[ d ][ 0 ]) 
				minMaxDim[ d ][ 0 ] = (float)tmp[ d ];

			if ( tmp[ d ] > minMaxDim[ d ][ 1 ]) 
				minMaxDim[ d ][ 1 ] = (float)tmp[ d ];
		}				
	}
	
	return minMaxDim;
}
 
Example 4
Source File: TransformUtils.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the min and max coordinate of the transformed image in each dimension
 * relative to the dimensions of the image it is based on. This is important
 * for computing bounding boxes.
 *
 * @param dimensions - the dimensions of the image
 * @param transform - the transformation
 *
 * @return - double[ numDimensions ][ 2 ], in the respective dimension d
 * double[ d ][ 0 ] is min, double[ d ][ 1 ] is max
 */
public static double[][] getMinMaxDim( final int[] dimensions, final CoordinateTransform transform )
{
	final int numDimensions = dimensions.length;

	final double[] tmp = new double[ numDimensions ];
	final double[][] minMaxDim = new double[ numDimensions ][ 2 ];

	for ( int d = 0; d < numDimensions; ++d )
	{
		minMaxDim[ d ][ 0 ] = Double.MAX_VALUE;
		minMaxDim[ d ][ 1 ] = -Double.MAX_VALUE;
	}

	// recursively get all corner points of the image, assuming they will still be the extremum points
	// in the transformed image
	final boolean[][] positions = new boolean[ Util.pow( 2, numDimensions ) ][ numDimensions ];
	Util.setCoordinateRecursive( numDimensions - 1, numDimensions, new int[ numDimensions ], positions );

	// get the min and max location for each dimension independently
	for ( int i = 0; i < positions.length; ++i )
	{
		for ( int d = 0; d < numDimensions; ++d )
		{
			if ( positions[ i ][ d ])
				tmp[ d ] = dimensions[ d ];
			else
				tmp[ d ] = 0;
		}

		transform.applyInPlace( tmp );

		for ( int d = 0; d < numDimensions; ++d )
		{
			if ( tmp[ d ] < minMaxDim[ d ][ 0 ])
				minMaxDim[ d ][ 0 ] = tmp[ d ];

			if ( tmp[ d ] > minMaxDim[ d ][ 1 ])
				minMaxDim[ d ][ 1 ] = tmp[ d ];
		}
	}

	return minMaxDim;
}