net.imglib2.view.Views.flatIterable()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(120)

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

Views.flatIterable介绍

[英]Return an IterableInterval having FlatIterationOrder. If the passed RandomAccessibleInterval is already an IterableInterval with FlatIterationOrder then it is returned directly (this is the case for ArrayImg). If not, then an IterableRandomAccessibleInterval is created.
[中]返回具有FlatIterationOrder的IterableInterval。如果传递的RandomAccessibleInterval已经是带有FlatIterationOrder的IterableInterval,则直接返回它(ArrayImg就是这种情况)。如果没有,则创建一个iTerableLandmaccessibleInterval。

代码示例

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

@Override
public IterableInterval<T> calculate(RandomAccessibleInterval<T> input) {
  return Views.flatIterable(input);
}

代码示例来源:origin: net.imagej/imagej-deprecated

/**
 * View on {@link Img} which is defined by a given Interval, but still is an
 * {@link Img}.
 * 
 * @param in Source interval for the view
 * @param fac <T> Factory to create img
 */
public ImgView( final RandomAccessibleInterval< T > in, ImgFactory< T > fac )
{
  super( in );
  factory = fac;
  ii = Views.flatIterable( in );
}

代码示例来源:origin: net.imglib2/imglib2

/**
 * View on {@link Img} which is defined by a given Interval, but still is an
 * {@link Img}.
 *
 * Deprecation: Use {@link ImgView#wrap(RandomAccessibleInterval, ImgFactory)}
 * to represent a RandomAccessibleInterval as an Img
 *
 * @param in
 *            Source interval for the view
 * @param fac
 *            T Factory to create img
 */
@Deprecated
public ImgView( final RandomAccessibleInterval< T > in, final ImgFactory< T > fac )
{
  super( in );
  factory = fac;
  ii = Views.flatIterable( in );
}

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

/**
 * View on {@link Img} which is defined by a given Interval, but still is an
 * {@link Img}.
 *
 * Deprecation: Use {@link ImgView#wrap(RandomAccessibleInterval, ImgFactory)}
 * to represent a RandomAccessibleInterval as an Img
 *
 * @param in
 *            Source interval for the view
 * @param fac
 *            T Factory to create img
 */
@Deprecated
public ImgView( final RandomAccessibleInterval< T > in, final ImgFactory< T > fac )
{
  super( in );
  factory = fac;
  ii = Views.flatIterable( in );
}

代码示例来源:origin: net.imglib2/imglib2

/**
 * Returns the pixels of an RandomAccessibleInterval of RealType as array of doubles.
 * The pixels are sorted in flat iteration order.
 */
public static double[] asDoubleArray( final RandomAccessibleInterval< ? extends RealType< ? > > rai )
{
  return asDoubleArray( Views.flatIterable( rai ) );
}

代码示例来源:origin: sc.fiji/bigdataviewer-core

public AccumulateProjector(
    final ArrayList< VolatileProjector > sourceProjectors,
    final ArrayList< ? extends RandomAccessible< ? extends A > > sources,
    final RandomAccessibleInterval< B > target,
    final int numThreads,
    final ExecutorService executorService )
{
  this.sourceProjectors = sourceProjectors;
  this.sources = new ArrayList<>();
  for ( final RandomAccessible< ? extends A > source : sources )
    this.sources.add( Views.flatIterable( Views.interval( source, target ) ) );
  this.target = target;
  this.iterableTarget = Views.flatIterable( target );
  this.numThreads = numThreads;
  this.executorService = executorService;
  lastFrameRenderNanoTime = -1;
}

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

/**
 * Returns the pixels of an RandomAccessibleInterval of RealType as array of doubles.
 * The pixels are sorted in flat iteration order.
 */
public static double[] asDoubleArray( final RandomAccessibleInterval< ? extends RealType< ? > > rai )
{
  return asDoubleArray( Views.flatIterable( rai ) );
}

代码示例来源:origin: net.imagej/imagej-deprecated

/**
 * TODO: No metadata is saved here..
 * 
 * @see SubImg
 * 
 */
public LabelingView( RandomAccessibleInterval< LabelingType< L >> in, LabelingFactory< L > fac )
{
  super( in );
  m_fac = fac;
  m_strategy = new DefaultROIStrategy< L, Labeling< L >>( this );
  m_ii = Views.flatIterable( in );
}

代码示例来源:origin: net.imglib2/imglib2-roi

/**
 * @param in
 *            the {@link RandomAccessibleInterval} to be wrapped
 * @param fac
 *            factory to create a new {@link Labeling}
 */
public LabelingView( final RandomAccessibleInterval< LabelingType< L > > in,
    final LabelingFactory< L > fac )
{
  super( in );
  m_fac = fac;
  m_strategy = new DefaultROIStrategy< L, Labeling< L > >( this );
  m_ii = Views.flatIterable( in );
}

代码示例来源:origin: net.preibisch/multiview-reconstruction

public static final void normalize( final RandomAccessibleInterval< FloatType > img )
  {
    float min = Float.MAX_VALUE;
    float max = -Float.MAX_VALUE;

    for ( final FloatType t : Views.flatIterable( img ) )
    {
      final float v = t.get();

      if ( v < min )
        min = v;

      if ( v > max )
        max = v;
    }

    for ( final FloatType t : Views.flatIterable( img ) )
      t.set( ( t.get() - min ) / ( max - min ) );
  }
}

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

private Cursor<T> getCube(
  final ExtendedRandomAccessibleInterval<T, RandomAccessibleInterval<T>> extended,
  final int cursorX, final int cursorY, final int cursorZ)
{
  return Views.flatIterable(Views.interval(extended, new FinalInterval(
    new long[] { cursorX, cursorY, cursorZ }, new long[] { cursorX + 1,
      cursorY + 1, cursorZ + 1 }))).cursor();
}

代码示例来源:origin: net.imglib2/imglib2-algorithms

/**
 * Compute the partial derivative of source in a particular dimension.
 *
 * @param source
 *            source image, has to provide valid data in the interval of the
 *            gradient image plus a one pixel border in dimension.
 * @param gradient
 *            output image
 * @param dimension
 *            along which dimension the partial derivatives are computed
 */
public static < T extends NumericType< T > > void gradientCentralDifference2( final RandomAccessible< T > source, final RandomAccessibleInterval< T > gradient, final int dimension )
{
  final Cursor< T > front = Views.flatIterable( Views.interval( source, Intervals.translate( gradient, 1, dimension ) ) ).cursor();
  final Cursor< T > back = Views.flatIterable( Views.interval( source, Intervals.translate( gradient, -1, dimension ) ) ).cursor();
  for( final T t : Views.flatIterable( gradient ) )
  {
    t.set( front.next() );
    t.sub( back.next() );
    t.mul( 0.5 );
  }
}

代码示例来源:origin: net.imglib2/imglib2-algorithm

/**
 * Compute the partial derivative (central difference approximation) of source
 * in a particular dimension:
 * {@code d_f( x ) = ( f( x + e ) - f( x - e ) ) / 2},
 * where {@code e} is the unit vector along that dimension.
 *
 * @param source
 *            source image, has to provide valid data in the interval of the
 *            gradient image plus a one pixel border in dimension.
 * @param gradient
 *            output image
 * @param dimension
 *            along which dimension the partial derivatives are computed
 */
public static < T extends NumericType< T > > void gradientCentralDifference2( final RandomAccessible< T > source, final RandomAccessibleInterval< T > gradient, final int dimension )
{
  final Cursor< T > front = Views.flatIterable( Views.interval( source, Intervals.translate( gradient, 1, dimension ) ) ).cursor();
  final Cursor< T > back = Views.flatIterable( Views.interval( source, Intervals.translate( gradient, -1, dimension ) ) ).cursor();
  for ( final T t : Views.flatIterable( gradient ) )
  {
    t.set( front.next() );
    t.sub( back.next() );
    t.mul( 0.5 );
  }
}

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

@Benchmark
public void gradient_niceAndSlow()
{
  final Cursor< DoubleType > front = Views.flatIterable( Views.interval( in, Intervals.translate( out, 1, 0 ) ) ).cursor();
  final Cursor< DoubleType > back = Views.flatIterable( Views.interval( in, Intervals.translate( out, -1, 0 ) ) ).cursor();
  for ( final DoubleType t : Views.flatIterable( out ) )
  {
    t.set( front.next() );
    t.sub( back.next() );
    t.mul( 0.5 );
  }
}

代码示例来源:origin: saalfeldlab/n5

/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  final File testDir = new File(testDirPath);
  testDir.mkdirs();
  if (!(testDir.exists() && testDir.isDirectory()))
    throw new IOException("Could not create benchmark directory for HDF5Utils benchmark.");
  data = new short[64 * 64 * 64];
  final ImagePlus imp = new Opener().openURL("https://imagej.nih.gov/ij/images/t1-head-raw.zip");
  final ImagePlusImg<UnsignedShortType, ?> img = (ImagePlusImg<UnsignedShortType, ?>)(Object)ImagePlusImgs.from(imp);
  final Cursor<UnsignedShortType> cursor = Views.flatIterable(Views.interval(img, new long[]{100, 100, 30}, new long[]{163, 163, 93})).cursor();
  for (int i = 0; i < data.length; ++i)
    data[i] = (short)cursor.next().get();
  n5 = new N5FSWriter(testDirPath);
}

代码示例来源:origin: net.imglib2/imglib2-algorithm

private static < T extends RealType< T >, U extends RealType< U > > void transformL1AlongDimension(
    final RandomAccessible< T > source,
    final RandomAccessibleInterval< U > target,
    final int dim,
    final double weight )
{
  final int lastDim = target.numDimensions() - 1;
  final long size = target.dimension( dim );
  final RealComposite< DoubleType > tmp = Views.collapseReal( createAppropriateOneDimensionalImage( size, new DoubleType() ) ).randomAccess().get();
  // do not permute if we already work on last dimension
  final Cursor< RealComposite< T > > s = Views.flatIterable( Views.collapseReal( dim == lastDim ? Views.interval( source, target ) : Views.permute( Views.interval( source, target ), dim, lastDim ) ) ).cursor();
  final Cursor< RealComposite< U > > t = Views.flatIterable( Views.collapseReal( dim == lastDim ? target : Views.permute( target, dim, lastDim ) ) ).cursor();
  while ( s.hasNext() )
  {
    final RealComposite< T > sourceComp = s.next();
    final RealComposite< U > targetComp = t.next();
    for ( long i = 0; i < size; ++i )
    {
      tmp.get( i ).set( sourceComp.get( i ).getRealDouble() );
    }
    transformL1SingleColumn( tmp, targetComp, weight, size );
  }
}

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

public void testPositionToIndex( final RandomAccessibleInterval< ? > interval )
{
  final long[] pos = new long[ dim.length ];
  final long[] min = Intervals.minAsLongArray( interval );
  for ( final Cursor< ? > cursor = Views.flatIterable( interval ).localizingCursor(); cursor.hasNext(); )
  {
    cursor.fwd();
    cursor.localize( pos );
    Assert.assertEquals( IntervalIndexer.positionWithOffsetToIndex( pos, dim, min ), IntervalIndexer.positionToIndexForInterval( cursor, interval ) );
  }
}

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

@Test
public void test() {
  // load test image
  Img<FloatType> watershedTestImg = openFloatImg(WatershedTest.class, "watershed_test_image.png");
  // threshold it
  RandomAccessibleInterval<BitType> thresholdedImg = ops.create().img(watershedTestImg, new BitType());
  ops.threshold().apply(Views.flatIterable(thresholdedImg), Views.flatIterable(watershedTestImg),
      new FloatType(1));
  // compute inverted distance transform and smooth it with gaussian
  // filtering
  final RandomAccessibleInterval<FloatType> distMap = ops.image().distancetransform(thresholdedImg);
  final RandomAccessibleInterval<FloatType> invertedDistMap = ops.create().img(distMap, new FloatType());
  ops.image().invert(Views.iterable(invertedDistMap), Views.iterable(distMap));
  final RandomAccessibleInterval<FloatType> gauss = ops.filter().gauss(invertedDistMap, 3, 3);
  testWithoutMask(gauss);
  testWithMask(gauss);
}

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

@Test
  public void defaultFlatIterableTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

    Cursor<DoubleType> il2 = Views.flatIterable(img).cursor();

    Cursor<DoubleType> opr = ops.transform().flatIterableView(img).cursor();

    while (il2.hasNext()) {
      il2.next();
      opr.next();
      assertEquals(il2.getDoublePosition(0), opr.getDoublePosition(0), 1e-10);
      assertEquals(il2.getDoublePosition(1), opr.getDoublePosition(1), 1e-10);
    }
  }
}

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

@Test
public void testIdentity()
{
  for ( int source = 0; source < numDimensions; ++source )
  {
    for ( int target = 0; target < numDimensions; ++ target ) 
    {
      
      if ( target == source ) continue;
      
      ShearTransform tf = new ShearTransform( numDimensions, target, source );
      AbstractShearTransform iv = tf.inverse();
      TransformView<FloatType> transformed = new TransformView< FloatType >( new TransformView< FloatType >( img, iv ), tf );
      
      ArrayCursor<FloatType> i = img.cursor();
      Cursor<FloatType> t      = Views.flatIterable( Views.interval( transformed, img ) ).cursor();
      
      while( t.hasNext() ) 
      {
        Assert.assertTrue( i.hasNext() );
        Assert.assertEquals( i.next().get(), t.next().get(), 0.0f );
      }
      Assert.assertFalse( i.hasNext() );
    }
  }
}

相关文章