Refine search
public HypersphereNeighborhoodLocalizableSampler( final RandomAccessible< T > source, final long radius, final HyperSphereNeighborhoodFactory< T > factory, Interval accessInterval ) { super( source.numDimensions() ); this.source = source; this.radius = radius; neighborhoodFactory = factory; currentPos = new long[ n ]; if ( accessInterval == null && source instanceof Interval ) accessInterval = ( Interval ) source; if ( accessInterval == null ) { sourceInterval = null; } else { final long[] accessMin = new long[ n ]; final long[] accessMax = new long[ n ]; accessInterval.min( accessMin ); accessInterval.max( accessMax ); for ( int d = 0; d < n; ++d ) { accessMin[ d ] -= radius; accessMax[ d ] += radius; } sourceInterval = new FinalInterval( accessMin, accessMax ); } currentNeighborhood = neighborhoodFactory.create( currentPos, radius, sourceInterval == null ? source.randomAccess() : source.randomAccess( sourceInterval ) ); }
public HyperSphereCursor( final RandomAccessible< T > source, final long[] center, final long radius ) { this.source = source; this.center = center.clone(); this.radius = radius; this.numDimensions = source.numDimensions(); this.maxDim = numDimensions - 1; this.r = new long[ numDimensions ]; this.s = new long[ numDimensions ]; this.randomAccess = source.randomAccess(); reset(); }
/** * copy src to dest * @param src : source, will not be modified * @param dest : destiantion, will be modified * @param <T> pixel type source * @param <S> pixel type destination */ public static <T extends RealType<T>, S extends RealType<S>> void copy(RandomAccessible< T > src, RandomAccessibleInterval< S > dest) { final Cursor< S > destCursor = Views.iterable( dest ).localizingCursor(); final RandomAccess< T > srcRA = src.randomAccess(); while (destCursor.hasNext()) { destCursor.fwd(); srcRA.setPosition( destCursor ); destCursor.get().setReal( srcRA.get().getRealDouble() ); } }
public static < T extends RealType< T > > void downsample( final RandomAccessible< T > input, final RandomAccessibleInterval< T > output, final int[] factor ) assert input.numDimensions() == output.numDimensions(); assert input.numDimensions() == factor.length; final int n = input.numDimensions(); final RectangleNeighborhoodFactory< T > f = RectangleNeighborhoodUnsafe.< T >factory(); final long[] dim = new long[ n ]; for ( int d = 0; d < n; ++d ) dim[ d ] = factor[ d ]; final Interval spanInterval = new FinalInterval( dim ); maxRequiredInput[ d ] += factor[ d ] - 1; final RandomAccessibleInterval< T > requiredInput = Views.interval( input, new FinalInterval( minRequiredInput, maxRequiredInput ) ); final double scale = 1.0 / size; final Cursor< T > out = Views.iterable( output ).localizingCursor(); while( out.hasNext() ) final T o = out.next(); for ( int d = 0; d < n; ++d ) block.setPosition( out.getLongPosition( d ) * factor[ d ], d ); double sum = 0; for ( final T i : block.get() ) sum += i.getRealDouble(); o.setReal( sum * scale );
private static final void copy( final long start, final long loopSize, final RandomAccessible< FloatType > source, final RandomAccessibleInterval< FloatType > block, final long[] offset ) { final int numDimensions = source.numDimensions(); final Cursor< FloatType > cursor = Views.iterable( block ).localizingCursor(); // define where we will query the RandomAccess on the source // (we say it is the entire block, although it is just a part of it, // but which part depends on the underlying container) final long[] min = new long[ numDimensions ]; final long[] max = new long[ numDimensions ]; for ( int d = 0; d < numDimensions; ++d ) { min[ d ] = offset[ d ]; max[ d ] = offset[ d ] + block.dimension( d ) - 1; } final RandomAccess< FloatType > randomAccess = source.randomAccess( new FinalInterval( min, max ) ); cursor.jumpFwd( start ); final long[] tmp = new long[ numDimensions ]; for ( long l = 0; l < loopSize; ++l ) { cursor.fwd(); cursor.localize( tmp ); for ( int d = 0; d < numDimensions; ++d ) tmp[ d ] += offset[ d ]; randomAccess.setPosition( tmp ); cursor.get().set( randomAccess.get() ); } }
public < F extends Interval & RandomAccessible< T > > AbstractOutOfBoundsValue( final F f ) { super( f.numDimensions() ); this.sampler = f.randomAccess(); dimension = new long[ n ]; f.dimensions( dimension ); min = new long[ n ]; f.min( min ); max = new long[ n ]; f.max( max ); dimIsOutOfBounds = new boolean[ n ]; }
final RandomAccess< Neighborhood< Object > > access = neighborhoodsRandomAccessible( accessible ).randomAccess(); access.setPosition( new long[ numDimensions ] ); final long[] min = LongStream.generate( () -> Long.MAX_VALUE ).limit( numDimensions ).toArray(); final long[] max = LongStream.generate( () -> Long.MIN_VALUE ).limit( numDimensions ).toArray(); for ( final Cursor< Object > cursor = access.get().localizingCursor(); cursor.hasNext(); ) cursor.fwd(); for ( int d = 0; d < numDimensions; ++d ) final long pos = cursor.getLongPosition( d ); min[ d ] = Math.min( pos, min[ d ] ); max[ d ] = Math.max( pos, max[ d ] ); return new FinalInterval( min, max );
final FinalInterval sourceInterval = new FinalInterval( min, max ); final Cursor< B > targetCursor = target.localizingCursor(); final RandomAccess< A > sourceRandomAccess = source.randomAccess( sourceInterval ); sourceRandomAccess.setPosition( position ); while ( targetCursor.hasNext() ) final B b = targetCursor.next(); sourceRandomAccess.setPosition( targetCursor.getLongPosition( X ), dimX ); sourceRandomAccess.setPosition( targetCursor.getLongPosition( Y ), dimY );
@Override public String call() throws Exception { final RandomAccess< T > r = input.randomAccess(); final int[] tmp = new int[ n ]; final Cursor< T > c = output.localizingCursor(); c.jumpFwd( portion.getStartPosition() ); for ( long j = 0; j < portion.getLoopSize(); ++j ) { final T t = c.next(); c.localize( tmp ); tmp[ d ] -= radius; r.setPosition( tmp ); float min = Float.MAX_VALUE; for ( int i = 0; i < filterExtent; ++i ) { min = Math.min( min, r.get().getRealFloat() ); r.fwd( d ); } t.setReal( min ); } return ""; } });
final FinalInterval interval = new FinalInterval( new long[] { offsetX, offsetY, offsetZ }, new long[] { offsetX + w - 1, offsetY + h - 1, offsetZ + d - 1 } ); final RandomAccess< FloatType > randomAccess = source.randomAccess( interval ); randomAccess.setPosition( tmp ); randomAccess.setPosition( offsetX, 0 ); blockArray[ i++ ] = randomAccess.get().get(); randomAccess.fwd( 0 );
protected < T extends BooleanType< T > > void calculate( final RandomAccessible< T > source, final IterableInterval< T > target ) { final RandomAccessible< Neighborhood< T > > accessible = shape.neighborhoodsRandomAccessible( source ); final RandomAccess< Neighborhood< T > > randomAccess = accessible.randomAccess( target ); final Cursor< T > cursorTarget = target.cursor(); final boolean[] table = getTable(); while ( cursorTarget.hasNext() ) { final T targetVal = cursorTarget.next(); randomAccess.setPosition( cursorTarget ); final Neighborhood< T > neighborhood = randomAccess.get(); final Cursor< T > nc = neighborhood.cursor(); int idx = 0; // Assume that the neighborhood obtained is of FlatIterationOrder, // and assemble the index using bitwise operations. while ( nc.hasNext() ) { idx <<= 1; idx |= nc.next().get() ? 1 : 0; } targetVal.set( table[ idx ] ); } }
/** * Get an instance of type T from a {@link RandomAccess} on accessible that * is positioned at the min of interval. * * @param accessible * @param interval * @return type instance */ private static < T extends NumericType< T > > T getType( final RandomAccessible< T > accessible, final Interval interval ) { final RandomAccess< T > a = accessible.randomAccess(); interval.min( a ); return a.get(); }
protected ClampingNLinearInterpolatorVolatileARGB( final RandomAccessible< T > randomAccessible ) { this( randomAccessible, randomAccessible.randomAccess().get() ); }
@Test public void testRandomAccessible() { long[] position = { 4, 2 }; int n = position.length; RandomAccessible< Localizable > randomAccessible = Localizables.randomAccessible( n ); RandomAccess< Localizable > randomAccess = randomAccessible.randomAccess(); assertEquals( n, randomAccessible.numDimensions() ); assertEquals( n, randomAccess.numDimensions() ); randomAccess.setPosition( position ); assertArrayEquals( position, Localizables.asLongArray( randomAccess.get() ) ); } }
@Test public void testMoveAxisUp() { RandomAccessible< Localizable > input = Localizables.randomAccessible( 4 ); RandomAccessible< Localizable > view = Views.moveAxis( input, 1, 3 ); RandomAccess< Localizable > ra = view.randomAccess(); ra.setPosition( new long[] {1, 3, 4, 2} ); assertArrayEquals( new long[] {1, 2, 3, 4}, Localizables.asLongArray( ra.get() ) ); }
/** * Define an interval on a RandomAccessible and translate it such that the * min corner is at the origin. It is the callers responsibility to ensure * that the source RandomAccessible is defined in the specified interval. * * @param randomAccessible * the source * @param interval * the interval on source that should be cut out and translated * to the origin. * @return a RandomAccessibleInterval */ public static < T > IntervalView< T > offsetInterval( final RandomAccessible< T > randomAccessible, final Interval interval ) { final int n = randomAccessible.numDimensions(); final long[] offset = new long[ n ]; final long[] min = new long[ n ]; final long[] max = new long[ n ]; interval.min( offset ); interval.max( max ); for ( int d = 0; d < n; ++d ) max[ d ] -= offset[ d ]; return Views.interval( Views.offset( randomAccessible, offset ), min, max ); }
@Override public boolean test( final Localizable l ) { final RandomAccess< B > accessor = ra.randomAccess(); accessor.setPosition( l ); return accessor.get().get(); }
/** * * Switch for calling convenience method with pre-defined distances. * */ public static enum DISTANCE_TYPE { /** * Squared Euclidian distance using {@link EuclidianDistanceIsotropic} or * {@link EuclidianDistanceAnisotropic}. */ EUCLIDIAN, /** * L1 distance using special case implementation. */ L1 }
@SuppressWarnings( { "unchecked", "rawtypes" } ) public InterpolatingSource( final RandomAccessible< T > source, final A sourceTransform, final Converter< ? super T, ARGBType > converter ) { final InterpolatorFactory< T, RandomAccessible< T > > nLinearInterpolatorFactory; if ( ARGBType.class.isInstance( source.randomAccess().get() ) ) nLinearInterpolatorFactory = ( InterpolatorFactory ) new NLinearInterpolatorARGBFactory(); else nLinearInterpolatorFactory = new NLinearInterpolatorFactory< >(); this.sourceTransform = sourceTransform; this.converter = converter; sourceInterpolants = new RealRandomAccessible[] { Views.interpolate( source, new NearestNeighborInterpolatorFactory< T >() ), Views.interpolate( source, nLinearInterpolatorFactory ) }; interpolation = 0; }
public VolatileHierarchyProjector( final List< ? extends RandomAccessible< A > > sources, final Converter< ? super A, B > converter, final RandomAccessibleInterval< B > target, final byte[] maskArray, final int numThreads, final ExecutorService executorService ) { super( Math.max( 2, sources.get( 0 ).numDimensions() ), converter, target ); this.sources.addAll( sources ); numInvalidLevels = sources.size(); this.maskArray = maskArray; mask = ArrayImgs.bytes( maskArray, target.dimension( 0 ), target.dimension( 1 ) ); iterableTarget = Views.iterable( target ); for ( int d = 2; d < min.length; ++d ) min[ d ] = max[ d ] = 0; max[ 0 ] = target.max( 0 ); max[ 1 ] = target.max( 1 ); sourceInterval = new FinalInterval( min, max ); width = ( int )target.dimension( 0 ); height = ( int )target.dimension( 1 ); cr = -width; this.numThreads = numThreads; this.executorService = executorService; lastFrameRenderNanoTime = -1; clearMask(); }