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());
}
}
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());
}
}
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());
}
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());
}
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);
}
Aggregations