Java Code Examples for net.imglib2.IterableInterval#cursor()

The following examples show how to use net.imglib2.IterableInterval#cursor() . 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 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 2
Source File: DilationTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testListDilate() {
	final List<Shape> shapes = new ArrayList<>();
	shapes.add(new DiamondShape(1));
	shapes.add(new DiamondShape(1));
	shapes.add(new RectangleShape(1, false));
	shapes.add(new HorizontalLineShape(2, 1, false));
	@SuppressWarnings("unchecked")
	final IterableInterval<ByteType> out1 = (IterableInterval<ByteType>) ops
		.run(ListDilate.class, IterableInterval.class, in, shapes, false);
	final Img<ByteType> out2 = Dilation.dilate(in, shapes, 1);
	final Cursor<ByteType> c1 = out1.cursor();
	final Cursor<ByteType> c2 = out2.cursor();
	while (c1.hasNext())
		assertEquals(c1.next().get(), c2.next().get());
}
 
Example 3
Source File: DilationTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testListDilateFull() {
	final List<Shape> shapes = new ArrayList<>();
	shapes.add(new DiamondShape(1));
	shapes.add(new DiamondShape(1));
	shapes.add(new RectangleShape(1, false));
	shapes.add(new HorizontalLineShape(2, 1, false));
	@SuppressWarnings("unchecked")
	final IterableInterval<ByteType> out1 = (IterableInterval<ByteType>) ops
		.run(ListDilate.class, IterableInterval.class, in, shapes, true);
	final Img<ByteType> out2 = Dilation.dilateFull(in, shapes, 1);
	final Cursor<ByteType> c1 = out1.cursor();
	final Cursor<ByteType> c2 = out2.cursor();
	while (c1.hasNext())
		assertEquals(c1.next().get(), c2.next().get());
}
 
Example 4
Source File: FFTTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected void assertRAIsEqual(final RandomAccessibleInterval<FloatType> rai1,
	final RandomAccessibleInterval<FloatType> rai2, final float delta)
{
	final IterableInterval<FloatType> rai1Iterator = Views.iterable(rai1);
	final IterableInterval<FloatType> rai2Iterator = Views.iterable(rai2);

	final Cursor<FloatType> c1 = rai1Iterator.cursor();
	final Cursor<FloatType> c2 = rai2Iterator.cursor();

	while (c1.hasNext()) {
		c1.fwd();
		c2.fwd();

		// assert that the inverse = the input within the error delta
		assertEquals(c1.get().getRealFloat(), c2.get().getRealFloat(), delta);
	}
}
 
Example 5
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 6
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 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 Cursor<I2> bCursor = b.cursor();
	final RandomAccess<O> cAccess = c.randomAccess();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		final long m = ctr == 0 ? startIndex + 1 : stepSize;
		aCursor.jumpFwd(m);
		bCursor.jumpFwd(m);
		cAccess.setPosition(aCursor);
		op.compute(aCursor.get(), bCursor.get(), cAccess.get());
	}
}
 
Example 7
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 8
Source File: IntegralCursorTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testIntegralCursor() {
	Shape rectangleShape = new RectangleShape(1, false);
	IterableInterval<Neighborhood<ByteType>> ii = rectangleShape
		.neighborhoodsSafe(img);
	Cursor<Neighborhood<ByteType>> cursor = ii.cursor();

	// Manually select the neighborhood that is centered on the image
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();

	IntegralCursor<ByteType> integralCursor = new IntegralCursor<>(
		(RectangleNeighborhood) cursor.get());

	assertEquals(integralCursor.next(), new ByteType((byte) 1));
	assertEquals(integralCursor.next(), new ByteType((byte) 2));
	assertEquals(integralCursor.next(), new ByteType((byte) 5));
	assertEquals(integralCursor.next(), new ByteType((byte) 4));
	assertFalse(integralCursor.hasNext());

	integralCursor.reset();

	assertEquals(integralCursor.next(), new ByteType((byte) 1));
	assertEquals(integralCursor.next(), new ByteType((byte) 2));
	assertEquals(integralCursor.next(), new ByteType((byte) 5));
	assertEquals(integralCursor.next(), new ByteType((byte) 4));
	assertFalse(integralCursor.hasNext());
}
 
Example 9
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 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 RandomAccess<I1> aAccess = a.randomAccess();
	final Cursor<I2> bCursor = b.localizingCursor();
	final Cursor<O> cCursor = c.cursor();
	while (bCursor.hasNext()) {
		bCursor.fwd();
		aAccess.setPosition(bCursor);
		op.compute(aAccess.get(), bCursor.get(), cCursor.next());
	}
}
 
Example 10
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 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 Cursor<I1> aCursor = a.localizingCursor();
	final RandomAccess<I2> bAccess = b.randomAccess();
	final Cursor<O> cCursor = c.cursor();
	while (aCursor.hasNext()) {
		aCursor.fwd();
		bAccess.setPosition(aCursor);
		op.compute(aCursor.get(), bAccess.get(), cCursor.next());
	}
}
 
Example 11
Source File: ImgLib2Util.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static <T extends RealType<T>, S extends RealType<S>> void copyRealImage(IterableInterval<T> source, RandomAccessibleInterval<S> dest) {
	RandomAccess<S> destRA = dest.randomAccess();
	Cursor<T> srcC = source.cursor();
	
	
	while (srcC.hasNext()){
		srcC.fwd();
		destRA.setPosition(srcC);
		destRA.get().setReal(srcC.get().getRealDouble());
	}
}
 
Example 12
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <I1, I2, O> void map(final IterableInterval<I1> a,
	final IterableInterval<I2> b, final RandomAccessibleInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op)
{
	final Cursor<I1> aCursor = a.localizingCursor();
	final Cursor<I2> bCursor = b.cursor();
	final RandomAccess<O> cAccess = c.randomAccess();
	while (aCursor.hasNext()) {
		aCursor.fwd();
		cAccess.setPosition(aCursor);
		op.compute(aCursor.get(), bCursor.next(), cAccess.get());
	}
}
 
Example 13
Source File: AbstractFeatureTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param dim dimensions of the image
 * @param radii of the ellipse
 * @param offset of the ellipse
 * @return an {@link Img} of {@link BitType} filled with a ellipse
 */
@SuppressWarnings({ "deprecation" })
public Img<UnsignedByteType> getEllipsedBitImage(final long[] dim,
	final double[] radii, final double[] offset)
{

	// create empty bittype image with desired dimensions
	final ArrayImg<UnsignedByteType, ByteArray> img = ArrayImgs.unsignedBytes(
		dim);

	// create ellipse
	final EllipseRegionOfInterest ellipse = new EllipseRegionOfInterest();
	ellipse.setRadii(radii);

	// set origin in the center of image
	final double[] origin = new double[dim.length];
	for (int i = 0; i < dim.length; i++)
		origin[i] = dim[i] / 2;
	ellipse.setOrigin(origin);

	// get iterable intervall and cursor of ellipse
	final IterableInterval<UnsignedByteType> ii = ellipse
		.getIterableIntervalOverROI(img);
	final Cursor<UnsignedByteType> cursor = ii.cursor();

	// fill image with ellipse
	while (cursor.hasNext()) {
		cursor.next();
		cursor.get().set(255);
	}

	return img;
}
 
Example 14
Source File: MapViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testIterableIntervalView() {
	@SuppressWarnings("unchecked")
	final IterableInterval<ByteType> res =
		(IterableInterval<ByteType>) ops.run(MapViewIIToII.class, in, op,
			new ByteType());

	final Cursor<ByteType> iterable = res.cursor();
	while (iterable.hasNext()) {
		assertEquals((byte) 10, iterable.next().get());
	}
}
 
Example 15
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 16
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 Cursor<A> argCursor = arg.cursor();
	final Cursor<A> inCursor = in.cursor();
	while (argCursor.hasNext()) {
		op.mutate2(argCursor.next(), inCursor.next());
	}
}
 
Example 17
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 18
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 Cursor<I> aCursor = a.cursor();
	final Cursor<O> bCursor = b.cursor();
	while (aCursor.hasNext()) {
		op.compute(aCursor.next(), bCursor.next());
	}
}
 
Example 19
Source File: DefaultFillHoles.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final RandomAccessibleInterval<T> op,
	final RandomAccessibleInterval<T> r)
{
	final IterableInterval<T> iterOp = Views.flatIterable(op);
	final IterableInterval<T> iterR = Views.flatIterable(r);

	long[] dim = new long[r.numDimensions()];
	r.dimensions(dim);
	Cursor<T> rc = iterR.cursor();
	Cursor<T> opc = iterOp.localizingCursor();
	// Fill with non background marker
	while (rc.hasNext()) {
		rc.next().setOne();
	}

	rc.reset();
	boolean border;
	// Flood fill from every background border voxel
	while (rc.hasNext()) {
		rc.next();
		opc.next();
		if (rc.get().get() && !opc.get().get()) {
			border = false;
			for (int i = 0; i < r.numDimensions(); i++) {
				if (rc.getLongPosition(i) == 0 || rc.getLongPosition(i) == dim[i] -
					1)
				{
					border = true;
					break;
				}
			}
			if (border) {
				floodFillComp.compute(op, rc, r);
			}
		}
	}
}
 
Example 20
Source File: LinearIntensityMap.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final static protected < T extends RealType< T > > void mapARGB(
		final IterableInterval< ARGBType > image,
		final IterableInterval< RealComposite< T > > coefficients )
{
	final Cursor< ARGBType > cs = image.cursor();
	final Cursor< RealComposite< T > > ct = coefficients.cursor();

	while ( cs.hasNext() )
	{
		final RealComposite< T > t = ct.next();
		final double alpha = t.get( 0 ).getRealDouble();
		final double beta = t.get( 1 ).getRealDouble();

		final ARGBType s = cs.next();
		final int argb = s.get();
		final int a = ( ( argb >> 24 ) & 0xff );
		final double r = ( ( argb >> 16 ) & 0xff ) * alpha + beta;
		final double g = ( ( argb >> 8 ) & 0xff ) * alpha + beta;
		final double b = ( argb & 0xff ) * alpha + beta;

		s.set(
				( a << 24 ) |
				( ( r < 0 ? 0 : r > 255 ? 255 : ( int )( r + 0.5 ) ) << 16 ) |
				( ( g < 0 ? 0 : g > 255 ? 255 : ( int )( g + 0.5 ) ) << 8 ) |
				( b < 0 ? 0 : b > 255 ? 255 : ( int )( b + 0.5 ) ) );
	}
}