@Override public IterableInterval<T> calculate(RandomAccessibleInterval<T> input) { return Views.flatIterable(input); }
/** * 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 ); }
/** * 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 ); }
/** * 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 ); }
/** * 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 ) ); }
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; }
/** * 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 ) ); }
/** * 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 ); }
/** * @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 ); }
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 ) ); } }
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(); }
/** * 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 ); } }
/** * 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 ); } }
@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 ); } }
/** * @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); }
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 ); } }
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 ) ); } }
@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); }
@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); } } }
@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() ); } } }