/** Test the op with a 2x2 square. The square is in the middle of a 4x4 img */ @Test public void testSquare() throws Exception { // SETUP final Img<BitType> img = ArrayImgs.bits(4, 4); final IntervalView<BitType> square = Views.offsetInterval(img, new long[] { 1, 1 }, new long[] { 2, 2 }); square.cursor().forEachRemaining(BitType::setOne); // EXECUTE final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Wrong number of foreground elements in interval", 4, countForeground(result)); final IntervalView<BitType> resultSquare = Views.offsetInterval(result, new long[] { 1, 1 }, new long[] { 2, 2 }); assertTrue("Wrong number of foreground elements in object", allForeground( resultSquare)); }
/** * Test the op with a 3x3x3x3 hypercube. The cube is in the middle of a * 5x5x5x5 img */ @Test public void testHyperCube() throws Exception { // SETUP final Img<BitType> img = ArrayImgs.bits(5, 5, 5, 5); final IntervalView<BitType> hyperCube = Views.offsetInterval(img, new long[] { 1, 1, 1, 1 }, new long[] { 3, 3, 3, 3 }); hyperCube.cursor().forEachRemaining(BitType::setOne); // EXECUTE final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Wrong number of foreground elements in interval", 80, countForeground(result)); final IntervalView<BitType> resultHyperCube = Views.offsetInterval(result, new long[] { 1, 1, 1, 1 }, new long[] { 3, 3, 3, 3 }); assertEquals("Wrong number of foreground elements in object", 80, countForeground(resultHyperCube)); assertPositionBackground(result, new long[] { 2, 2, 2, 2 }); }
/** * Test the op with a 3x3 square starting from (0,1) in a 5x5 img without * excluding edges * * @see Outline#compute(RandomAccessibleInterval, Boolean, * RandomAccessibleInterval) * @see #testEdgeSquare() */ @Test public void testEdgeSquareExcludeEdgesFalse() throws Exception { // SETUP final Img<BitType> img = ArrayImgs.bits(5, 5); final IntervalView<BitType> square = Views.offsetInterval(img, new long[] { 0, 1 }, new long[] { 3, 3 }); square.cursor().forEachRemaining(BitType::setOne); final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.FALSE); assertEquals("Wrong number of foreground elements in interval", 8, countForeground(result)); final IntervalView<BitType> resultSquare = Views.offsetInterval(result, new long[] { 0, 1 }, new long[] { 3, 3 }); assertEquals("Wrong number of foreground elements in object", 8, countForeground(resultSquare)); assertPositionBackground(result, new long[] { 1, 2 }); }
/** * Test the op with a 3x3 square starting from (0,1) in a 5x5 img * * @see Outline#compute(RandomAccessibleInterval, Boolean, * RandomAccessibleInterval) * @see #testEdgeSquare() */ @Test public void testEdgeSquare() throws Exception { // SETUP final Img<BitType> img = ArrayImgs.bits(5, 5); final IntervalView<BitType> square = Views.offsetInterval(img, new long[] { 0, 1 }, new long[] { 3, 3 }); square.cursor().forEachRemaining(BitType::setOne); // EXECUTION final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Wrong number of foreground elements in interval", 7, countForeground(result)); final IntervalView<BitType> resultSquare = Views.offsetInterval(result, new long[] { 0, 1 }, new long[] { 3, 3 }); assertEquals("Wrong number of foreground elements in object", 7, countForeground(resultSquare)); assertPositionBackground(result, new long[] { 0, 2 }); assertPositionBackground(result, new long[] { 1, 2 }); }
/** * Test the op with a 3x3 square with a hole in the middle. The square is in * the middle of a 5x5 img */ @Test public void testOutlineSquare() throws Exception { // SETUP final Img<BitType> img = ArrayImgs.bits(5, 5); final IntervalView<BitType> square = Views.offsetInterval(img, new long[] { 1, 1 }, new long[] { 3, 3 }); square.cursor().forEachRemaining(BitType::setOne); final RandomAccess<BitType> access = square.randomAccess(); access.setPosition(new long[] { 1, 1 }); access.get().setZero(); // EXECUTION final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Wrong number of foreground elements in interval", 8, countForeground(result)); final IntervalView<BitType> resultSquare = Views.offsetInterval(result, new long[] { 1, 1 }, new long[] { 3, 3 }); assertEquals("Wrong number of foreground elements in object", 8, countForeground(resultSquare)); assertPositionBackground(result, new long[] { 2, 2 }); }