net.imglib2.img.Img.forEach()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(299)

本文整理了Java中net.imglib2.img.Img.forEach()方法的一些代码示例,展示了Img.forEach()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Img.forEach()方法的具体详情如下:
包路径:net.imglib2.img.Img
类名称:Img
方法名:forEach

Img.forEach介绍

暂无

代码示例

代码示例来源:origin: imglib/imglib2

  1. private RandomAccessibleInterval< IntType > randomImage( final int randomSeed )
  2. {
  3. final Img< IntType > result = ArrayImgs.ints( 3, 2, 5 );
  4. final Random random = new Random( randomSeed );
  5. result.forEach( x -> x.set( random.nextInt() ) );
  6. return Views.translate( result, random.nextInt(), random.nextInt(), random.nextInt() );
  7. }

代码示例来源:origin: imglib/imglib2

  1. @Test
  2. public void testIntervalLoop()
  3. {
  4. // setup
  5. final Img< IntType > img = ArrayImgs.ints( 1, 20, 5 );
  6. final RandomAccess< IntType > ra = img.randomAccess();
  7. // process
  8. final Runnable loop = LoopUtils.createIntervalLoop( ra, img,
  9. () -> ra.get().set( 42 ) );
  10. loop.run();
  11. // test
  12. img.forEach( value -> assertEquals( 42, value.get() ) );
  13. }
  14. }

代码示例来源:origin: imagej/imagej-ops

  1. /** Test the op with an interval that's full of foreground elements */
  2. @Test
  3. public void testAllForeground() throws Exception {
  4. // SETUP
  5. final Img<BitType> img = ArrayImgs.bits(3, 3, 3);
  6. img.forEach(BitType::setOne);
  7. // EXECUTE
  8. final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
  9. Boolean.TRUE);
  10. // VERIFY
  11. assertEquals("Output should contain no foreground", 0, countForeground(
  12. result));
  13. }

代码示例来源:origin: imglib/imglib2

  1. @Test
  2. public void testLoopLine()
  3. {
  4. // setup
  5. final Img< IntType > img = ArrayImgs.ints( 1, 1, 5 );
  6. final RandomAccess< IntType > ra = img.randomAccess();
  7. // process
  8. final Runnable loop = LoopUtils.createLineLoop( ra, img.dimension( 2 ), 2,
  9. () -> ra.get().set( 42 ) );
  10. loop.run();
  11. // test
  12. img.forEach( value -> assertEquals( 42, value.get() ) );
  13. }

代码示例来源:origin: imagej/imagej-ops

  1. @Test
  2. public void testIsNeighborhoodEmpty() throws Exception {
  3. final Img<BitType> img = ArrayImgs.bits(2, 2, 2);
  4. Octant<BitType> octant = new Octant<>(img);
  5. octant.setNeighborhood(1, 1, 1);
  6. assertTrue("Neighborhood should be empty", octant.isNeighborhoodEmpty());
  7. img.forEach(BitType::setOne);
  8. octant.setNeighborhood(1, 1, 1);
  9. assertFalse("Neighborhood should not be empty", octant.isNeighborhoodEmpty());
  10. }

代码示例来源:origin: imagej/imagej-ops

  1. @Test
  2. public void testAllForeground() {
  3. // SETUP
  4. final double scalingPow = DoubleStream.generate(() -> SCALING).limit(
  5. DIMENSIONS).reduce((i, j) -> i * j).orElse(0);
  6. final double[] expectedCounts = DoubleStream.iterate(1.0, i -> i *
  7. scalingPow).map(Math::log).limit(ITERATIONS).toArray();
  8. final Img<BitType> img = ArrayImgs.bits(TEST_DIMS);
  9. img.forEach(BitType::setOne);
  10. // EXECUTE
  11. final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
  12. .boxCount(img, MAX_SIZE, MIN_SIZE, SCALING);
  13. // VERIFY
  14. for (int i = 0; i < ITERATIONS; i++) {
  15. assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12);
  16. assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
  17. }
  18. }

相关文章