use of net.imglib2.algorithm.neighborhood.Shape in project imagej-ops by imagej.
the class NonLinearFiltersTest method before.
/**
* Initialize images.
*
* @throws Exception
*/
@Before
public void before() throws Exception {
in = generateByteArrayTestImg(true, new long[] { 10, 10 });
out = generateByteArrayTestImg(false, new long[] { 10, 10 });
shape = new RectangleShape(1, false);
}
use of net.imglib2.algorithm.neighborhood.Shape in project imagej-ops by imagej.
the class NonLinearFiltersTest method testMedianFilter.
/**
* @see MedianFilterOp
* @see DefaultMedianFilter
*/
@Test
public void testMedianFilter() {
ops.run(MedianFilterOp.class, out, in, shape, oobFactory);
ArrayList<ByteType> items = new ArrayList<>();
NeighborhoodsIterableInterval<ByteType> neighborhoods = shape.neighborhoods(Views.interval(Views.extendMirrorSingle(in), in));
for (ByteType t : neighborhoods.firstElement()) {
items.add(t.copy());
}
Collections.sort(items);
assertEquals(items.get(5).get(), out.firstElement().get());
}
use of net.imglib2.algorithm.neighborhood.Shape 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.Shape 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.Shape in project imagej-ops by imagej.
the class BlackTopHatTest method testListBlackTopHat.
@Test
public void testListBlackTopHat() {
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(ListBlackTopHat.class, IterableInterval.class, in, shapes);
final Img<ByteType> out2 = BlackTopHat.blackTopHat(in, shapes, 1);
assertIterationsEqual(out2, out1);
}
Aggregations