Java Code Examples for net.imglib2.util.Intervals#translate()

The following examples show how to use net.imglib2.util.Intervals#translate() . 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: FractalSpimDataGenerator.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param start the first interval
 * @param n number of tiles in x
 * @param m number of tiles in y
 * @param overlap overlap e (0-1)
 * @return intervals
 */
public static List<Interval> generateTileList(Interval start, int n, int m, double overlap)
{
	List<Interval> res = new ArrayList<>();
	for (int x = 0; x < n; ++x){
		for (int y = 0; y < m; ++y){
			
			Interval tInterval = new FinalInterval( start );
			tInterval = Intervals.translate( tInterval, (long) ( x * (1 - overlap) * start.dimension( 0 ) ), 0 );
			tInterval = Intervals.translate( tInterval, (long) ( y * (1 - overlap) * start.dimension( 1 ) ), 1 );
			res.add( tInterval );
		}
	}
	return res;
}
 
Example 2
Source File: PhaseCorrelationTest.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testPCNegativeShift() {
	
	// TODO: very large shifts (nearly no overlap) lead to incorrect shift determination (as expected)
	// maybe we can optimize behaviour in this situation
	Img< FloatType > img = ArrayImgs.floats( 200, 200 );
	Random rnd = new Random( seed );
	
	for( FloatType t : img )
		t.set( rnd.nextFloat());
	
	long shiftX = -2;
	long shiftY = -2;
	
	FinalInterval interval1 = new FinalInterval(new long[] {50, 50});
	FinalInterval interval2 = Intervals.translate(interval1, shiftX, 0);
	interval2 = Intervals.translate(interval2, shiftY, 1);

	int [] extension = new int[img.numDimensions()];
	Arrays.fill(extension, 10);
	
	RandomAccessibleInterval<FloatType> pcm = PhaseCorrelation2.calculatePCM(
			Views.zeroMin(Views.interval(Views.extendZero( img ), interval1)),
			Views.zeroMin(Views.interval(Views.extendZero( img ), interval2)),
			extension, new ArrayImgFactory<FloatType>(), 
			new FloatType(), new ArrayImgFactory<ComplexFloatType>(), new ComplexFloatType(), Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
	
	PhaseCorrelationPeak2 shiftPeak = PhaseCorrelation2.getShift(pcm,
			Views.zeroMin(Views.interval(Views.extendZero( img ), interval1)),
			Views.zeroMin(Views.interval(Views.extendZero( img ), interval2)),
			20, 0, false, Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
	
	long[] expected = new long[]{shiftX, shiftY};
	long[] found = new long[img.numDimensions()];
	
	
	
	shiftPeak.getShift().localize(found);
	System.out.println( Util.printCoordinates( found ) );
	
	assertArrayEquals(expected, found);
	
}
 
Example 3
Source File: PhaseCorrelationTest.java    From BigStitcher with GNU General Public License v2.0 3 votes vote down vote up
@Test
public void testPC() {
	
	// TODO: very large shifts (nearly no overlap) lead to incorrect shift determination (as expected)
	// maybe we can optimize behaviour in this situation
	Img< FloatType > img = ArrayImgs.floats( 200, 200 );
	Random rnd = new Random( seed );
	
	for( FloatType t : img )
		t.set( rnd.nextFloat());
	
	long shiftX = 28;
	long shiftY = 0;
	
	FinalInterval interval1 = new FinalInterval(new long[] {50, 50});
	FinalInterval interval2 = Intervals.translate(interval1, shiftX, 0);
	interval2 = Intervals.translate(interval2, shiftY, 1);

	
	int [] extension = new int[img.numDimensions()];
	Arrays.fill(extension, 10);
	
	RandomAccessibleInterval<FloatType> pcm = PhaseCorrelation2.calculatePCM(Views.interval(img, interval1), Views.zeroMin(Views.interval(img, interval2)), extension, new ArrayImgFactory<FloatType>(), 
			new FloatType(), new ArrayImgFactory<ComplexFloatType>(), new ComplexFloatType(), Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
	
	PhaseCorrelationPeak2 shiftPeak = PhaseCorrelation2.getShift(pcm, Views.interval(img, interval1), Views.zeroMin(Views.interval(img, interval2)), 20, 0, false, Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
	
	long[] expected = new long[]{shiftX, shiftY};
	long[] found = new long[img.numDimensions()];
	
	
	
	shiftPeak.getShift().localize(found);
	
	assertArrayEquals(expected, found);
	
}