Search in sources :

Example 16 with Cursor

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

the class NormalizeTest method testNormalize.

@Test
public void testNormalize() {
    Img<ByteType> in = generateByteArrayTestImg(true, 5, 5);
    Img<ByteType> out = in.factory().create(in, new ByteType());
    ops.run(NormalizeIIComputer.class, out, in);
    final Pair<ByteType, ByteType> minMax2 = ops.stats().minMax(out);
    assertEquals(minMax2.getA().get(), Byte.MIN_VALUE);
    assertEquals(minMax2.getB().get(), Byte.MAX_VALUE);
    final IterableInterval<ByteType> lazyOut = ops.image().normalize(in);
    final IterableInterval<ByteType> notLazyOut = ops.image().normalize(in, null, null, null, null, false);
    final Cursor<ByteType> outCursor = out.cursor();
    final Cursor<ByteType> lazyCursor = lazyOut.cursor();
    final Cursor<ByteType> notLazyCursor = notLazyOut.cursor();
    while (outCursor.hasNext()) {
        assertEquals(outCursor.next().get(), lazyCursor.next().get());
        assertEquals(outCursor.get().get(), notLazyCursor.next().get());
    }
}
Also used : ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 17 with Cursor

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

the class DilationTest method testListDilateFull.

@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());
}
Also used : DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) Shape(net.imglib2.algorithm.neighborhood.Shape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) HorizontalLineShape(net.imglib2.algorithm.neighborhood.HorizontalLineShape) DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) ArrayList(java.util.ArrayList) ByteType(net.imglib2.type.numeric.integer.ByteType) HorizontalLineShape(net.imglib2.algorithm.neighborhood.HorizontalLineShape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) IterableInterval(net.imglib2.IterableInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 18 with Cursor

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

the class DilationTest method testSingleDilate.

@Test
public void testSingleDilate() {
    final Shape shape = new DiamondShape(1);
    @SuppressWarnings("unchecked") final Img<ByteType> out1 = (Img<ByteType>) ops.run(DefaultDilate.class, Img.class, in, shape, false);
    final Img<ByteType> out2 = Dilation.dilate(in, shape, 1);
    final Cursor<ByteType> c1 = out1.cursor();
    final Cursor<ByteType> c2 = out2.cursor();
    while (c1.hasNext()) assertEquals(c1.next().get(), c2.next().get());
}
Also used : Img(net.imglib2.img.Img) DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) Shape(net.imglib2.algorithm.neighborhood.Shape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) HorizontalLineShape(net.imglib2.algorithm.neighborhood.HorizontalLineShape) DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 19 with Cursor

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

the class DilationTest method testSingleDilateFull.

@Test
public void testSingleDilateFull() {
    final Shape shape = new DiamondShape(1);
    @SuppressWarnings("unchecked") final Img<ByteType> out1 = (Img<ByteType>) ops.run(DefaultDilate.class, Img.class, in, shape, true);
    final Img<ByteType> out2 = Dilation.dilateFull(in, shape, 1);
    final Cursor<ByteType> c1 = out1.cursor();
    final Cursor<ByteType> c2 = out2.cursor();
    while (c1.hasNext()) assertEquals(c1.next().get(), c2.next().get());
}
Also used : Img(net.imglib2.img.Img) DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) Shape(net.imglib2.algorithm.neighborhood.Shape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) HorizontalLineShape(net.imglib2.algorithm.neighborhood.HorizontalLineShape) DiamondShape(net.imglib2.algorithm.neighborhood.DiamondShape) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 20 with Cursor

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

the class ImageMomentsTest method createImg.

@BeforeClass
public static void createImg() {
    Img<UnsignedByteType> tmp = ArrayImgs.unsignedBytes(new long[] { 100, 100 });
    Random rand = new Random(1234567890L);
    final Cursor<UnsignedByteType> cursor = tmp.cursor();
    while (cursor.hasNext()) {
        cursor.next().set(rand.nextInt((int) tmp.firstElement().getMaxValue()));
    }
    img = tmp;
}
Also used : Random(java.util.Random) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) BeforeClass(org.junit.BeforeClass)

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