Java Code Examples for net.imglib2.RandomAccessible#numDimensions()

The following examples show how to use net.imglib2.RandomAccessible#numDimensions() . 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: SimpleInterruptibleProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public SimpleInterruptibleProjectorPreMultiply(
		final RandomAccessible<A> source,
		final Converter<? super A, ARGBType> converter,
		final RandomAccessibleInterval<ARGBType> target,
		final int numThreads,
		final ExecutorService executorService)
{
	super(source.numDimensions(), converter, target);
	this.source = source;
	this.numThreads = numThreads;
	this.executorService = executorService;
	lastFrameRenderNanoTime = -1;
}
 
Example 2
Source File: AccessBoxRandomAccessible.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public AccessBoxRandomAccessible(final RandomAccessible<T> source)
{
	this.source = source;
	min = new long[source.numDimensions()];
	max = new long[source.numDimensions()];
	sourceAccess = source.randomAccess();
}
 
Example 3
Source File: AccessBoxRandomAccessibleOnGet.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public AccessBoxRandomAccessibleOnGet(final RandomAccessible<T> source)
{
	this.source = source;
	min = new long[source.numDimensions()];
	max = new long[source.numDimensions()];
	sourceAccess = source.randomAccess();
}
 
Example 4
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 5
Source File: CostesSignificanceTest.java    From Colocalisation_Analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method drives the creation of RegionOfInterest-Cursors on the given image.
 * It does not matter if those generated blocks are used for reading and/or
 * writing. The resulting blocks are put into the given list and are in the
 * responsibility of the caller, i.e. he or she must make sure the cursors get
 * closed on some point in time.
 *
 * @param img The image to create cursors on.
 * @param blockList The list to put newly created cursors into
 * @param offset
 * @param size
 */
protected void generateBlocks(RandomAccessible<T> img, List<IterableInterval<T>> blockList,
		double[] offset, double[] size)
		throws MissingPreconditionException {
	// get the number of dimensions
	int nrDimensions = img.numDimensions();
	if (nrDimensions == 2)
	{ // for a 2D image...
		generateBlocksXY(img, blockList, offset, size);
	}
	else if (nrDimensions == 3)
	{ // for a 3D image...
		final double depth = size[2];
		double z;
		double originalZ = offset[2];
		// go through the depth in steps of block depth
		for ( z = psfRadius[2]; z <= depth; z += psfRadius[2] ) {

			offset[2] = originalZ + z - psfRadius[2];
			generateBlocksXY(img, blockList, offset, size);
		}
		// check is we need to add a out of bounds strategy cursor
		if (z > depth) {
			offset[2] = originalZ + z - psfRadius[2];
			generateBlocksXY(img, blockList, offset, size);
		}
		offset[2] = originalZ;
	}
	else
		throw new MissingPreconditionException("Currently only 2D and 3D images are supported.");
}
 
Example 6
Source File: RestrictPainting.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static <T, U> void restrictTo(
		final RandomAccessible<Pair<T, U>> source,
		final RandomAccessible<UnsignedLongType> mask,
		final Localizable seed,
		final Shape shape,
		final Predicate<T> backgroundFilter,
		final Predicate<U> canvasFilter)
{
	final int n = source.numDimensions();

	final RandomAccessible<Pair<Pair<T, U>, UnsignedLongType>> paired = Views.pair(source, mask);

	final TLongList[] coordinates = new TLongList[n];
	for (int d = 0; d < n; ++d)
	{
		coordinates[d] = new TLongArrayList();
		coordinates[d].add(seed.getLongPosition(d));
	}

	final RandomAccessible<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>> neighborhood       = shape
			.neighborhoodsRandomAccessible(
			paired);
	final RandomAccess<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>>     neighborhoodAccess = neighborhood
			.randomAccess();

	final RandomAccess<UnsignedLongType> targetAccess = mask.randomAccess();
	targetAccess.setPosition(seed);
	targetAccess.get().set(1);

	final UnsignedLongType zero = new UnsignedLongType(0);
	final UnsignedLongType one  = new UnsignedLongType(1);
	final UnsignedLongType two  = new UnsignedLongType(2);

	for (int i = 0; i < coordinates[0].size(); ++i)
	{
		for (int d = 0; d < n; ++d)
		{
			neighborhoodAccess.setPosition(coordinates[d].get(i), d);
		}

		final Cursor<Pair<Pair<T, U>, UnsignedLongType>> neighborhoodCursor = neighborhoodAccess.get().cursor();

		while (neighborhoodCursor.hasNext())
		{
			final Pair<Pair<T, U>, UnsignedLongType> p                   = neighborhoodCursor.next();
			final UnsignedLongType                   m                   = p.getB();
			final Pair<T, U>                         backgroundAndCanvas = p.getA();
			if (m.valueEquals(zero) && canvasFilter.test(backgroundAndCanvas.getB()))
			{
				// If background is same as at seed, mark mask with two
				// (==not active), else with one (==active).
				m.set(backgroundFilter.test(backgroundAndCanvas.getA()) ? two : one);
				for (int d = 0; d < n; ++d)
				{
					coordinates[d].add(neighborhoodCursor.getLongPosition(d));
				}
			}

		}

		if (i > CLEANUP_THRESHOLD)
		{
			for (int d = 0; d < coordinates.length; ++d)
			{
				final TLongList c = coordinates[d];
				coordinates[d] = c.subList(i, c.size());
			}
			i = 0;
		}

	}
}
 
Example 7
Source File: FourNeighborhoodExtrema.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static < T extends RealType< T > > ArrayList< Pair< Localizable, Double > > findMax( final RandomAccessible< T > img, final Interval region, final int maxN )
	{
		final Cursor< T > c = Views.iterable( Views.interval( img, region ) ).localizingCursor();
		final RandomAccess< T > r = img.randomAccess();
		final int n = img.numDimensions();

		final ArrayList< Pair< Localizable, Double > > list = new ArrayList< Pair< Localizable, Double > >();

		for ( int i = 0; i < maxN; ++i )
			list.add( new ValuePair< Localizable, Double >( null, -Double.MAX_VALUE ) );

A:		while ( c.hasNext() )
		{
			final double type = c.next().getRealDouble();
			r.setPosition( c );

			for ( int d = 0; d < n; ++d )
			{
				r.fwd( d );
				if ( type < r.get().getRealDouble() )
					continue A;
	
				r.bck( d );
				r.bck( d );
				
				if ( type < r.get().getRealDouble() )
					continue A;

				r.fwd( d );
			}

			
			for ( int i = maxN - 1; i >= 0; --i )
			{
				if ( type < list.get( i ).getB() )
				{
					if ( i == maxN - 1 )
					{
						continue A;
					}
					else
					{
						list.add( i + 1, new ValuePair< Localizable, Double >( new Point( c ), type ) );
						list.remove( maxN );
						continue A;
					}
				}
			}

			list.add( 0, new ValuePair< Localizable, Double >( new Point( c ), type ) );
			list.remove( maxN );
		}

		// remove all null elements
		for ( int i = maxN -1; i >= 0; --i )
			if ( list.get( i ).getA() == null )
				list.remove(  i );

		return list;
	}
 
Example 8
Source File: ConvolveNaiveC.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final RandomAccessible<I> input,
	final RandomAccessibleInterval<O> output)
{
	// TODO: try a decomposition of the kernel into n 1-dim kernels

	final long[] min = new long[input.numDimensions()];
	final long[] max = new long[input.numDimensions()];

	for (int d = 0; d < kernel.numDimensions(); d++) {
		min[d] = -kernel.dimension(d);
		max[d] = kernel.dimension(d) + output.dimension(d);
	}

	final RandomAccess<I> inRA =
		input.randomAccess(new FinalInterval(min, max));

	final Cursor<K> kernelC = Views.iterable(kernel).localizingCursor();

	final Cursor<O> outC = Views.iterable(output).localizingCursor();

	final long[] pos = new long[input.numDimensions()];
	final long[] kernelRadius = new long[kernel.numDimensions()];
	for (int i = 0; i < kernelRadius.length; i++) {
		kernelRadius[i] = kernel.dimension(i) / 2;
	}

	float val;

	while (outC.hasNext()) {
		// image
		outC.fwd();
		outC.localize(pos);

		// kernel inlined version of the method convolve
		val = 0;
		inRA.setPosition(pos);

		kernelC.reset();
		while (kernelC.hasNext()) {
			kernelC.fwd();

			for (int i = 0; i < kernelRadius.length; i++) {
				// dimension can have zero extension e.g. vertical 1d kernel
				if (kernelRadius[i] > 0) {
					inRA.setPosition(pos[i] + kernelC.getLongPosition(i) -
						kernelRadius[i], i);
				}
			}

			val += inRA.get().getRealDouble() * kernelC.get().getRealDouble();
		}

		outC.get().setReal(val);
	}
}
 
Example 9
Source File: Align.java    From BigStitcher with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Compute the partial derivatives of source every dimension.
 *
 * @param source
 *            n dimensional source image, has to provide valid data in the
 *            interval of the gradient image plus a one pixel border in
 *            every dimension.
 * @param target
 *            n+1 dimensional output image. Dimension n is used to index the
 *            partial derivative. For example, the partial derivative by Y
 *            is stored in slice n=1.
 * @param <T> pixel type source
 * @param <S> pixel type target
 */
public static < T extends RealType< T >, S extends RealType<S> > void gradients(
		final RandomAccessible< T > source,
		final RandomAccessibleInterval< S > target )
{
	final int n = source.numDimensions();
	for ( int d = 0; d < n; ++d )
		gradient( source, Views.hyperSlice( target, n, d ), d );
}