Search in sources :

Example 21 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class JoinTest method testJoinInplaceAndComputer.

@Test
public void testJoinInplaceAndComputer() {
    final Op op = ops.op(DefaultJoinInplaceAndComputer.class, out, in, inplaceOp, computerOp);
    op.run();
    // test
    final Cursor<ByteType> c = out.cursor();
    while (c.hasNext()) {
        assertEquals(2, c.next().get());
    }
}
Also used : AbstractUnaryComputerOp(net.imagej.ops.special.computer.AbstractUnaryComputerOp) Op(net.imagej.ops.Op) MapOp(net.imagej.ops.map.MapOp) UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) UnaryInplaceOp(net.imagej.ops.special.inplace.UnaryInplaceOp) AbstractUnaryInplaceOp(net.imagej.ops.special.inplace.AbstractUnaryInplaceOp) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 22 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class JoinTest method testJoin2Inplaces.

@Test
public void testJoin2Inplaces() {
    final Op op = ops.op(DefaultJoin2Inplaces.class, in, inplaceOp, inplaceOp);
    op.run();
    // test
    final Cursor<ByteType> c = in.cursor();
    while (c.hasNext()) {
        assertEquals(2, c.next().get());
    }
}
Also used : AbstractUnaryComputerOp(net.imagej.ops.special.computer.AbstractUnaryComputerOp) Op(net.imagej.ops.Op) MapOp(net.imagej.ops.map.MapOp) UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) UnaryInplaceOp(net.imagej.ops.special.inplace.UnaryInplaceOp) AbstractUnaryInplaceOp(net.imagej.ops.special.inplace.AbstractUnaryInplaceOp) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 23 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class MeanTest method testMean.

@Test
public void testMean() {
    final Img<ByteType> image = generateByteArrayTestImg(true, 40, 50);
    final DoubleType mean = new DoubleType();
    ops.run(IterableMean.class, mean, image);
    assertEquals(1.0 / 15.625, mean.get(), 0.0);
    Cursor<ByteType> c = image.cursor();
    // this time lets just make every value 100
    while (c.hasNext()) {
        c.fwd();
        c.get().setReal(100.0);
    }
    ops.run(IterableMean.class, mean, image);
    // the mean should be 100
    assertEquals(100.0, mean.get(), 0.0);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 24 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class FlatIterableViewTest method defaultFlatIterableTest.

@Test
public void defaultFlatIterableTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    Cursor<DoubleType> il2 = Views.flatIterable(img).cursor();
    Cursor<DoubleType> opr = ops.transform().flatIterableView(img).cursor();
    while (il2.hasNext()) {
        il2.next();
        opr.next();
        assertEquals(il2.getDoublePosition(0), opr.getDoublePosition(0), 1e-10);
        assertEquals(il2.getDoublePosition(1), opr.getDoublePosition(1), 1e-10);
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 25 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class IntervalViewTest method intervalMinMaxTest.

@Test
public void intervalMinMaxTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    Random r = new Random();
    for (DoubleType d : img) {
        d.set(r.nextDouble());
    }
    Cursor<DoubleType> il2 = Views.interval(img, new long[] { 1, 1 }, new long[] { 8, 9 }).localizingCursor();
    RandomAccess<DoubleType> opr = ops.transform().intervalView(img, new long[] { 1, 1 }, new long[] { 8, 9 }).randomAccess();
    while (il2.hasNext()) {
        DoubleType e = il2.next();
        opr.setPosition(il2);
        assertEquals(e.get(), opr.get().get(), 1e-10);
    }
}
Also used : Random(java.util.Random) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)43 AbstractOpTest (net.imagej.ops.AbstractOpTest)40 DoubleType (net.imglib2.type.numeric.real.DoubleType)30 Random (java.util.Random)21 FinalInterval (net.imglib2.FinalInterval)21 ByteType (net.imglib2.type.numeric.integer.ByteType)14 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)12 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)11 ArrayList (java.util.ArrayList)10 DiamondShape (net.imglib2.algorithm.neighborhood.DiamondShape)10 Shape (net.imglib2.algorithm.neighborhood.Shape)10 BitType (net.imglib2.type.logic.BitType)8 FloatType (net.imglib2.type.numeric.real.FloatType)8 Img (net.imglib2.img.Img)7 HorizontalLineShape (net.imglib2.algorithm.neighborhood.HorizontalLineShape)6 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)6 Before (org.junit.Before)6 IterableInterval (net.imglib2.IterableInterval)4 Point (net.imglib2.Point)4 RealPoint (net.imglib2.RealPoint)4