Java Code Examples for net.imglib2.Cursor#jumpFwd()

The following examples show how to use net.imglib2.Cursor#jumpFwd() . 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: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <I1, I2, O> void map(final IterableInterval<I1> a,
	final IterableInterval<I2> b, final IterableInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op, final long startIndex,
	final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<I1> aCursor = a.cursor();
	final Cursor<I2> bCursor = b.cursor();
	final Cursor<O> cCursor = c.cursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		final long m = ctr == 0 ? startIndex + 1 : stepSize;
		aCursor.jumpFwd(m);
		bCursor.jumpFwd(m);
		cCursor.jumpFwd(m);
		op.compute(aCursor.get(), bCursor.get(), cCursor.get());
	}
}
 
Example 2
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <I1, I2, O> void map(final IterableInterval<I1> a,
	final RandomAccessibleInterval<I2> b, final IterableInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op, final long startIndex,
	final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<I1> aCursor = a.localizingCursor();
	final RandomAccess<I2> bAccess = b.randomAccess();
	final Cursor<O> cCursor = c.cursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		final long m = ctr == 0 ? startIndex + 1 : stepSize;
		aCursor.jumpFwd(m);
		cCursor.jumpFwd(m);
		bAccess.setPosition(aCursor);
		op.compute(aCursor.get(), bAccess.get(), cCursor.get());
	}
}
 
Example 3
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <I1, I2, O> void map(final RandomAccessibleInterval<I1> a,
	final IterableInterval<I2> b, final IterableInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op, final long startIndex,
	final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final RandomAccess<I1> aAccess = a.randomAccess();
	final Cursor<I2> bCursor = b.localizingCursor();
	final Cursor<O> cCursor = c.cursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		final long m = ctr == 0 ? startIndex + 1 : stepSize;
		bCursor.jumpFwd(m);
		cCursor.jumpFwd(m);
		aAccess.setPosition(bCursor);
		op.compute(aAccess.get(), bCursor.get(), cCursor.get());
	}
}
 
Example 4
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <I1, I2, O> void map(final IterableInterval<I1> a,
	final RandomAccessibleInterval<I2> b, final RandomAccessibleInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op, final long startIndex,
	final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<I1> aCursor = a.localizingCursor();
	final RandomAccess<I2> bAccess = b.randomAccess();
	final RandomAccess<O> cAccess = c.randomAccess();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		aCursor.jumpFwd(ctr == 0 ? startIndex + 1 : stepSize);
		bAccess.setPosition(aCursor);
		cAccess.setPosition(aCursor);
		op.compute(aCursor.get(), bAccess.get(), cAccess.get());
	}
}
 
Example 5
Source File: TransformInput.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String call() throws Exception 
{
	final NLinearInterpolatorFactory< FloatType > f = new NLinearInterpolatorFactory< FloatType >();
	
	// make the interpolators and get the transformations
	final RealRandomAccess< FloatType > ir = Views.interpolate( Views.extendMirrorSingle( img ), f ).realRandomAccess();
	final Cursor< FloatType > cursor = Views.iterable( transformedImg ).localizingCursor();

	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
		loop( cursor, ir, transform, s, t, offsetX, offsetY, offsetZ, imgSizeX, imgSizeY, imgSizeZ );
	
	return portion + " finished successfully (transform input & no weights).";
}
 
Example 6
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <I, O> void map(final IterableInterval<I> a,
	final IterableInterval<O> b, final UnaryComputerOp<I, O> op,
	final long startIndex, final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<I> aCursor = a.cursor();
	final Cursor<O> bCursor = b.cursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		final long m = ctr == 0 ? startIndex + 1 : stepSize;
		aCursor.jumpFwd(m);
		bCursor.jumpFwd(m);
		op.compute(aCursor.get(), bCursor.get());
	}
}
 
Example 7
Source File: Block.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private static final void copy( final long start, final long loopSize, final RandomAccessible< FloatType > source, final RandomAccessibleInterval< FloatType > block, final long[] offset )
{
	final int numDimensions = source.numDimensions();
	final Cursor< FloatType > cursor = Views.iterable( block ).localizingCursor();

	// define where we will query the RandomAccess on the source
	// (we say it is the entire block, although it is just a part of it,
	// but which part depends on the underlying container)
	final long[] min = new long[ numDimensions ];
	final long[] max = new long[ numDimensions ];
	
	for ( int d = 0; d < numDimensions; ++d )
	{
		min[ d ] = offset[ d ];
		max[ d ] = offset[ d ] + block.dimension( d ) - 1;
	}

	final RandomAccess< FloatType > randomAccess = source.randomAccess( new FinalInterval( min, max ) );

	cursor.jumpFwd( start );

	final long[] tmp = new long[ numDimensions ];

	for ( long l = 0; l < loopSize; ++l )
	{
		cursor.fwd();
		cursor.localize( tmp );
		
		for ( int d = 0; d < numDimensions; ++d )
			tmp[ d ] += offset[ d ];
		
		randomAccess.setPosition( tmp );
		cursor.get().set( randomAccess.get() );
	}
}
 
Example 8
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <A> void inplace(final IterableInterval<A> arg,
	final IterableInterval<A> in, final BinaryInplaceOp<A, A> op,
	final long startIndex, final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<A> argCursor = arg.cursor();
	final Cursor<A> inCursor = in.cursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		final long m = ctr == 0 ? startIndex + 1 : stepSize;
		argCursor.jumpFwd(m);
		inCursor.jumpFwd(m);
		op.mutate2(argCursor.get(), inCursor.get());
	}
}
 
Example 9
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <A, I> void inplace(final RandomAccessibleInterval<A> arg,
	final IterableInterval<I> in, final BinaryInplace1Op<A, I, A> op,
	final long startIndex, final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final RandomAccess<A> argAccess = arg.randomAccess();
	final Cursor<I> inCursor = in.localizingCursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		inCursor.jumpFwd(ctr == 0 ? startIndex + 1 : stepSize);
		argAccess.setPosition(inCursor);
		op.mutate1(argAccess.get(), inCursor.get());
	}
}
 
Example 10
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <A, I> void inplace(final IterableInterval<A> arg,
	final RandomAccessibleInterval<I> in, final BinaryInplace1Op<A, I, A> op,
	final long startIndex, final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<A> argCursor = arg.localizingCursor();
	final RandomAccess<I> inAccess = in.randomAccess();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		argCursor.jumpFwd(ctr == 0 ? startIndex + 1 : stepSize);
		inAccess.setPosition(argCursor);
		op.mutate1(argCursor.get(), inAccess.get());
	}
}
 
Example 11
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <A, I> void inplace(final IterableInterval<A> arg,
	final IterableInterval<I> in, final BinaryInplace1Op<A, I, A> op,
	final long startIndex, final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<A> argCursor = arg.cursor();
	final Cursor<I> inCursor = in.cursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		final long m = ctr == 0 ? startIndex + 1 : stepSize;
		argCursor.jumpFwd(m);
		inCursor.jumpFwd(m);
		op.mutate1(argCursor.get(), inCursor.get());
	}
}
 
Example 12
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <I, O> void map(final RandomAccessibleInterval<I> a,
	final IterableInterval<O> b, final UnaryComputerOp<I, O> op,
	final long startIndex, final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final RandomAccess<I> aAccess = a.randomAccess();
	final Cursor<O> bCursor = b.localizingCursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		bCursor.jumpFwd(ctr == 0 ? startIndex + 1 : stepSize);
		aAccess.setPosition(bCursor);
		op.compute(aAccess.get(), bCursor.get());
	}
}
 
Example 13
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <O> void map(final IterableInterval<O> a,
	final NullaryComputerOp<O> op, final long startIndex, final long stepSize,
	final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<O> aCursor = a.cursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		aCursor.jumpFwd(ctr == 0 ? startIndex + 1 : stepSize);
		op.compute(aCursor.get());
	}
}
 
Example 14
Source File: ProcessParalellPortionWeights.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators, weights and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final ArrayList< ArrayList< RealRandomAccess< FloatType > > > weightAccess = new ArrayList< ArrayList< RealRandomAccess< FloatType > > >();
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
		
		final ArrayList< RealRandomAccess< FloatType > > list = new ArrayList< RealRandomAccess< FloatType > >();

		for ( final RealRandomAccessible< FloatType > rra : weights.get( i ) )
			list.add( rra.realRandomAccess() );
		
		weightAccess.add( list );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		double sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				
				double w = 1;
				
				for ( final RealRandomAccess< FloatType > weight : weightAccess.get( i ) )
				{
					weight.setPosition( t );
					w *= weight.get().get();
				}
				
				sum += r.get().getRealDouble() * w;
				sumW += w;
			}
		}
		
		if ( sumW > 0 )
			v.setReal( sum / sumW );
	}
	
	return portion + " finished successfully (many weights).";
}
 
Example 15
Source File: ProcessParalellPortion.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		int sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				sum += r.get().getRealDouble();
				++sumW;
			}
		}
		
		if ( sumW > 0 )
			v.setReal( sum / sumW );
	}
	
	return portion + " finished successfully (no weights).";
}
 
Example 16
Source File: ProcessIndependentPortion.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	// make the interpolators and get the transformations
	final RealRandomAccess< T > r = Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess();
	final int[] imgSize = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		transform.applyInverse( t, s );
		
		if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSize[ 0 ], imgSize[ 1 ], imgSize[ 2 ] ) )
		{
			r.setPosition( t );
			v.setReal( r.get().getRealFloat() );
		}
	}
	
	return portion + " finished successfully (individual fusion, no weights).";
}
 
Example 17
Source File: ProcessParalellPortionWeight.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators, weights and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final ArrayList< RealRandomAccess< FloatType > > weightAccess = new ArrayList< RealRandomAccess< FloatType > >();
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
					
		weightAccess.add( weights.get( i ).realRandomAccess() );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		double sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				
				final RealRandomAccess< FloatType > weight = weightAccess.get( i );
				weight.setPosition( t );
				
				final double w = weight.get().get();
				
				sum += r.get().getRealDouble() * w;
				sumW += w;
			}
		}
		
		if ( sumW > 0 )
			v.setReal( sum / sumW );
	}
	
	return portion + " finished successfully (one weight).";
}
 
Example 18
Source File: HistogramOfOrientedGradients2D.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void compute(RandomAccessibleInterval<T> in, RandomAccessibleInterval<T> out) {
	final RandomAccessible<FloatType> convertedIn = Converters.convert(Views.extendMirrorDouble(in),
			converterToFloat, new FloatType());

	// compute partial derivative for each dimension
	RandomAccessibleInterval<FloatType> derivative0 = createImgOp.calculate();
	RandomAccessibleInterval<FloatType> derivative1 = createImgOp.calculate();

	// case of grayscale image
	if (in.numDimensions() == 2) {
		PartialDerivative.gradientCentralDifference(convertedIn, derivative0, 0);
		PartialDerivative.gradientCentralDifference(convertedIn, derivative1, 1);
	}
	// case of color image
	else {
		List<RandomAccessibleInterval<FloatType>> listDerivs0 = new ArrayList<>();
		List<RandomAccessibleInterval<FloatType>> listDerivs1 = new ArrayList<>();
		for (int i = 0; i < in.dimension(2); i++) {
			final RandomAccessibleInterval<FloatType> deriv0 = createImgOp.calculate();
			final RandomAccessibleInterval<FloatType> deriv1 = createImgOp.calculate();
			PartialDerivative.gradientCentralDifference(
					Views.interval(convertedIn, new long[] { 0, 0, i }, new long[] { in.max(0), in.max(1), i }),
					deriv0, 0);
			PartialDerivative.gradientCentralDifference(
					Views.interval(convertedIn, new long[] { 0, 0, i }, new long[] { in.max(0), in.max(1), i }),
					deriv1, 1);
			listDerivs0.add(deriv0);
			listDerivs1.add(deriv1);
		}
		derivative0 = Converters.convert(Views.collapse(Views.stack(listDerivs0)), converterGetMax,
				new FloatType());
		derivative1 = Converters.convert(Views.collapse(Views.stack(listDerivs1)), converterGetMax,
				new FloatType());
	}
	final RandomAccessibleInterval<FloatType> finalderivative0 = derivative0;
	final RandomAccessibleInterval<FloatType> finalderivative1 = derivative1;

	// compute angles and magnitudes
	final RandomAccessibleInterval<FloatType> angles = createImgOp.calculate();
	final RandomAccessibleInterval<FloatType> magnitudes = createImgOp.calculate();

	final CursorBasedChunk chunkable = new CursorBasedChunk() {

		@Override
		public void execute(long startIndex, long stepSize, long numSteps) {
			final Cursor<FloatType> cursorAngles = Views.flatIterable(angles).localizingCursor();
			final Cursor<FloatType> cursorMagnitudes = Views.flatIterable(magnitudes).localizingCursor();
			final Cursor<FloatType> cursorDerivative0 = Views.flatIterable(finalderivative0).localizingCursor();
			final Cursor<FloatType> cursorDerivative1 = Views.flatIterable(finalderivative1).localizingCursor();

			setToStart(cursorAngles, startIndex);
			setToStart(cursorMagnitudes, startIndex);
			setToStart(cursorDerivative0, startIndex);
			setToStart(cursorDerivative1, startIndex);

			for (long i = 0; i < numSteps; i++) {
				final float x = cursorDerivative0.get().getRealFloat();
				final float y = cursorDerivative1.get().getRealFloat();
				cursorAngles.get().setReal(getAngle(x, y));
				cursorMagnitudes.get().setReal(getMagnitude(x, y));

				cursorAngles.jumpFwd(stepSize);
				cursorMagnitudes.jumpFwd(stepSize);
				cursorDerivative0.jumpFwd(stepSize);
				cursorDerivative1.jumpFwd(stepSize);
			}
		}
	};

	ops().thread().chunker(chunkable, Views.flatIterable(magnitudes).size());

	// stores each Thread to execute
	final List<Callable<Void>> listCallables = new ArrayList<>();

	// compute descriptor (default 3x3, i.e. 9 channels: one channel for
	// each bin)
	final RectangleShape shape = new RectangleShape(spanOfNeighborhood, false);
	final NeighborhoodsAccessible<FloatType> neighborHood = shape.neighborhoodsRandomAccessible(angles);

	for (int i = 0; i < in.dimension(0); i++) {
		listCallables.add(new ComputeDescriptor(Views.interval(convertedIn, in), i, angles.randomAccess(),
				magnitudes.randomAccess(), (RandomAccess<FloatType>) out.randomAccess(),
				neighborHood.randomAccess()));
	}

	try {
		es.invokeAll(listCallables);
	} catch (final InterruptedException e) {
		throw new RuntimeException(e);
	}

	listCallables.clear();
}
 
Example 19
Source File: ProcessSequentialPortion.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String call() throws Exception 
{
	final int numViews = imgs.size();
	
	// make the interpolators and get the transformations
	final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
	final int[][] imgSizes = new int[ numViews ][ 3 ];
	
	for ( int i = 0; i < numViews; ++i )
	{
		final RandomAccessibleInterval< T > img = imgs.get( i );
		imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
		
		interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
	}

	final Cursor< T > cursor = fusedImg.localizingCursor();
	final Cursor< FloatType > cursorW = weightImg.cursor();
	
	final float[] s = new float[ 3 ];
	final float[] t = new float[ 3 ];
	
	cursor.jumpFwd( portion.getStartPosition() );
	cursorW.jumpFwd( portion.getStartPosition() );
	
	for ( int j = 0; j < portion.getLoopSize(); ++j )
	{
		// move img cursor forward any get the value (saves one access)
		final T v = cursor.next();
		cursor.localize( s );
		
		// move weight cursor forward and get the value 
		final FloatType w = cursorW.next();
		
		if ( doDownSampling )
		{
			s[ 0 ] *= downSampling;
			s[ 1 ] *= downSampling;
			s[ 2 ] *= downSampling;
		}
		
		s[ 0 ] += bb.min( 0 );
		s[ 1 ] += bb.min( 1 );
		s[ 2 ] += bb.min( 2 );
		
		double sum = 0;
		int sumW = 0;
		
		for ( int i = 0; i < numViews; ++i )
		{				
			transforms[ i ].applyInverse( t, s );
			
			if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
			{
				final RealRandomAccess< T > r = interpolators.get( i );
				r.setPosition( t );
				sum += r.get().getRealDouble();
				++sumW;
			}
		}
		
		if ( sumW > 0 )
		{
			v.setReal( v.getRealFloat() + sum );
			w.set( w.get() + sumW );
		}
	}
	
	return portion + " finished successfully (no weights).";
}
 
Example 20
Source File: CursorBasedChunk.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void setToStart(final Cursor<?> c, long startIndex) {
	c.reset();
	c.jumpFwd(startIndex + 1);
}