private RandomAccessibleInterval< IntType > randomImage( final int randomSeed ) { final Img< IntType > result = ArrayImgs.ints( 3, 2, 5 ); final Random random = new Random( randomSeed ); result.forEach( x -> x.set( random.nextInt() ) ); return Views.translate( result, random.nextInt(), random.nextInt(), random.nextInt() ); }
@Test public void testIntervalLoop() { // setup final Img< IntType > img = ArrayImgs.ints( 1, 20, 5 ); final RandomAccess< IntType > ra = img.randomAccess(); // process final Runnable loop = LoopUtils.createIntervalLoop( ra, img, () -> ra.get().set( 42 ) ); loop.run(); // test img.forEach( value -> assertEquals( 42, value.get() ) ); } }
/** Test the op with an interval that's full of foreground elements */ @Test public void testAllForeground() throws Exception { // SETUP final Img<BitType> img = ArrayImgs.bits(3, 3, 3); img.forEach(BitType::setOne); // EXECUTE final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Output should contain no foreground", 0, countForeground( result)); }
@Test public void testLoopLine() { // setup final Img< IntType > img = ArrayImgs.ints( 1, 1, 5 ); final RandomAccess< IntType > ra = img.randomAccess(); // process final Runnable loop = LoopUtils.createLineLoop( ra, img.dimension( 2 ), 2, () -> ra.get().set( 42 ) ); loop.run(); // test img.forEach( value -> assertEquals( 42, value.get() ) ); }
@Test public void testIsNeighborhoodEmpty() throws Exception { final Img<BitType> img = ArrayImgs.bits(2, 2, 2); Octant<BitType> octant = new Octant<>(img); octant.setNeighborhood(1, 1, 1); assertTrue("Neighborhood should be empty", octant.isNeighborhoodEmpty()); img.forEach(BitType::setOne); octant.setNeighborhood(1, 1, 1); assertFalse("Neighborhood should not be empty", octant.isNeighborhoodEmpty()); }
@Test public void testAllForeground() { // SETUP final double scalingPow = DoubleStream.generate(() -> SCALING).limit( DIMENSIONS).reduce((i, j) -> i * j).orElse(0); final double[] expectedCounts = DoubleStream.iterate(1.0, i -> i * scalingPow).map(Math::log).limit(ITERATIONS).toArray(); final Img<BitType> img = ArrayImgs.bits(TEST_DIMS); img.forEach(BitType::setOne); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, MAX_SIZE, MIN_SIZE, SCALING); // VERIFY for (int i = 0; i < ITERATIONS; i++) { assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12); assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12); } }