Search in sources :

Example 6 with Neighborhood

use of net.imglib2.algorithm.neighborhood.Neighborhood in project imagej-ops by imagej.

the class MapNeighborhoodTest method testMapNeighborhoodsAccess.

/**
 * Test if every neighborhood pixel of the image was really accessed during
 * the map operation.
 *
 * @see DefaultMapNeighborhood
 */
@Test
public void testMapNeighborhoodsAccess() {
    final Op mapOp = ops.op(DefaultMapNeighborhood.class, out, in, new RectangleShape(1, false), new CountNeighbors());
    mapOp.run();
    for (final ByteType t : out) {
        assertEquals(9, t.get());
    }
}
Also used : AbstractUnaryComputerOp(net.imagej.ops.special.computer.AbstractUnaryComputerOp) Op(net.imagej.ops.Op) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 7 with Neighborhood

use of net.imglib2.algorithm.neighborhood.Neighborhood in project imagej-ops by imagej.

the class MapNeighborhoodTest method testMapNeighborhoodsWithCenterAccess.

/**
 * Test if every neighborhood pixel of the image was really accessed during
 * the map operation.
 *
 * @see MapNeighborhoodWithCenter
 */
@Test
public void testMapNeighborhoodsWithCenterAccess() {
    final Op mapOp = ops.op(MapNeighborhoodWithCenter.class, out, in, new RectangleShape(1, false), new CountNeighborsWithCenter());
    mapOp.run();
    for (final ByteType t : out) {
        assertEquals(9, t.get());
    }
    for (final ByteType t : in) {
        assertEquals(9, t.get());
    }
}
Also used : AbstractUnaryComputerOp(net.imagej.ops.special.computer.AbstractUnaryComputerOp) Op(net.imagej.ops.Op) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 8 with Neighborhood

use of net.imglib2.algorithm.neighborhood.Neighborhood in project imagej-ops by imagej.

the class IntegralCursorTest method testIntegralCursor.

@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());
}
Also used : Shape(net.imglib2.algorithm.neighborhood.Shape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) ByteType(net.imglib2.type.numeric.integer.ByteType) Neighborhood(net.imglib2.algorithm.neighborhood.Neighborhood) RectangleNeighborhood(net.imglib2.algorithm.neighborhood.RectangleNeighborhood) Test(org.junit.Test)

Example 9 with Neighborhood

use of net.imglib2.algorithm.neighborhood.Neighborhood in project imagej-ops by imagej.

the class IntegralCursorTest method testIntegralCursorCopyConstructor.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testIntegralCursorCopyConstructor() {
    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));
    IntegralCursor<ByteType> integralCursor2 = new IntegralCursor<>(integralCursor);
    assertEquals(integralCursor2.next(), new ByteType((byte) 5));
    assertEquals(integralCursor2.next(), new ByteType((byte) 4));
    assertFalse(integralCursor2.hasNext());
}
Also used : Shape(net.imglib2.algorithm.neighborhood.Shape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) RectangleShape(net.imglib2.algorithm.neighborhood.RectangleShape) ByteType(net.imglib2.type.numeric.integer.ByteType) Neighborhood(net.imglib2.algorithm.neighborhood.Neighborhood) RectangleNeighborhood(net.imglib2.algorithm.neighborhood.RectangleNeighborhood) Test(org.junit.Test)

Example 10 with Neighborhood

use of net.imglib2.algorithm.neighborhood.Neighborhood in project imagej-ops by imagej.

the class WatershedSeededTest method testWithoutMask.

@SuppressWarnings("unchecked")
private void testWithoutMask(final RandomAccessibleInterval<FloatType> in, final ImgLabeling<Integer, IntType> seeds) {
    // create mask which is 1 everywhere
    long[] dims = new long[in.numDimensions()];
    in.dimensions(dims);
    Img<BitType> mask = ArrayImgs.bits(dims);
    for (BitType b : mask) {
        b.setOne();
    }
    /*
		 * use 8-connected neighborhood
		 */
    // compute result without watersheds
    ImgLabeling<Integer, IntType> out = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, true, false);
    assertResults(in, out, seeds, mask, false, false);
    // compute result with watersheds
    ImgLabeling<Integer, IntType> out2 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, true, true);
    assertResults(in, out2, seeds, mask, true, false);
    /*
		 * use 4-connected neighborhood
		 */
    // compute result without watersheds
    ImgLabeling<Integer, IntType> out3 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, false, false);
    assertResults(in, out3, seeds, mask, false, false);
    // compute result with watersheds
    ImgLabeling<Integer, IntType> out4 = (ImgLabeling<Integer, IntType>) ops.run(WatershedSeeded.class, null, in, seeds, false, true);
    assertResults(in, out4, seeds, mask, true, false);
}
Also used : BitType(net.imglib2.type.logic.BitType) ImgLabeling(net.imglib2.roi.labeling.ImgLabeling) IntType(net.imglib2.type.numeric.integer.IntType)

Aggregations

BitType (net.imglib2.type.logic.BitType)11 Ops (net.imagej.ops.Ops)7 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)7 UnaryComputerOp (net.imagej.ops.special.computer.UnaryComputerOp)6 IntType (net.imglib2.type.numeric.integer.IntType)6 DoubleType (net.imglib2.type.numeric.real.DoubleType)6 LocalThresholdMethod (net.imagej.ops.threshold.LocalThresholdMethod)5 Shape (net.imglib2.algorithm.neighborhood.Shape)5 ImgLabeling (net.imglib2.roi.labeling.ImgLabeling)5 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)4 Neighborhood (net.imglib2.algorithm.neighborhood.Neighborhood)4 ByteType (net.imglib2.type.numeric.integer.ByteType)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 AbstractOpTest (net.imagej.ops.AbstractOpTest)2 Op (net.imagej.ops.Op)2 AbstractUnaryComputerOp (net.imagej.ops.special.computer.AbstractUnaryComputerOp)2 Interval (net.imglib2.Interval)2 RandomAccess (net.imglib2.RandomAccess)2 DiamondShape (net.imglib2.algorithm.neighborhood.DiamondShape)2