Refine search
private Interval shiftInterval( Interval interval, long[] offset ) { long[] min = new long[ offset.length ]; long[] max = new long[ offset.length ]; for ( int d = 0; d < interval.numDimensions(); d++ ) { min[ d ] = interval.min( d ) - offset[ d ]; max[ d ] = min[ d ] + interval.dimension( d ) - 1; } return new FinalInterval( min, max ); }
public static Interval trimInterval( final Interval interval ) { final long[] min = new long[ interval.numDimensions() ]; final long[] max = new long[ interval.numDimensions() ]; for ( int d = 0; d < interval.numDimensions(); ++d ) { min[ d ] = interval.min( d ) + 10; max[ d ] = interval.max( d ) - 10; } return new FinalInterval( min, max ); } }
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 ]; }
/** * Tests weather two intervals are equal in their min / max */ public static boolean equals( final Interval a, final Interval b ) { if ( a.numDimensions() != b.numDimensions() ) return false; for ( int d = 0; d < a.numDimensions(); ++d ) if ( a.min( d ) != b.min( d ) || a.max( d ) != b.max( d ) ) return false; return true; }
/** * Get the size of the Y-dimension. If it is a one-dimensional source, return 1. * * @param interval * @return 1 if only-dimensional, else the size */ protected static int getDimension1Size( final Interval interval ) { if ( interval.numDimensions() == 1 ) return 1; return ( int ) interval.dimension( 1 ); }
/** * {@link RandomAccessibleInterval} with same sice as target is returned * * @param src * {@link RandomAccessibleInterval} to be adjusted * @param target * {@link Interval} describing the resulting sizes * @return Adjusted {@link RandomAccessibleInterval} */ public static <T> RandomAccessibleInterval<T> synchronizeDimensionality( final RandomAccessibleInterval<T> src, final Interval target) { RandomAccessibleInterval<T> res = src; // Check direction of conversion if (intervalEquals(src, target)) return res; // adjust dimensions if (res.numDimensions() < target.numDimensions()) { for (int d = res.numDimensions(); d < target.numDimensions(); d++) { res = Views.addDimension(res, target.min(d), target.max(d)); } } else { for (int d = res.numDimensions() - 1; d >= target.numDimensions(); --d) res = Views.hyperSlice(res, d, 0); } long[] resDims = new long[res.numDimensions()]; res.dimensions(resDims); return Views.interval(Views.extendBorder(res), target); }
public DiamondNeighborhoodLocalizableSampler( final RandomAccessible< T > source, final long radius, final DiamondNeighborhoodFactory< T > factory, Interval accessInterval ) { super( source.numDimensions() ); this.source = source; this.radius = radius; this.factory = factory; this.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 ] = currentPos[ d ] - radius; accessMax[ d ] = currentPos[ d ] + radius; } sourceInterval = new FinalInterval( accessMin, accessMax ); } this.currentNeighborhood = factory.create( currentPos, radius, sourceInterval == null ? source.randomAccess() : source.randomAccess( sourceInterval ) ); }
final public static < R extends RealType< R > > void convolve( final RandomAccessible< R > img, final Interval imgInterval, final RandomAccessible< R > kernel, final Interval kernelInterval, final RandomAccessibleInterval< R > output, final ImgFactory< ComplexFloatType > factory ) final int numDimensions = imgInterval.numDimensions(); newDimensions[ d ] = (int)imgInterval.dimension( d ) + (int)kernelInterval.dimension( d ) - 1; min[ d ] = kernelInterval.min( d ) + kernelInterval.dimension( d ) / 2; max[ d ] = min[ d ] + kernelConvolutionInterval.dimension( d ) - 1; final RandomAccessibleInterval< R > kernelInput = Views.interval( Views.extendPeriodic( Views.interval( kernel, kernelConvolutionInterval ) ), new FinalInterval( min, max ) ); final RandomAccessibleInterval< R > imgInput = Views.interval( img, imgConvolutionInterval );
/** * Creates a virtual construct that transforms and zero-mins using a user-defined outofbounds & interpolation. * * @param input - the input image * @param transform - the affine transformation * @param boundingBox - the bounding box (after transformation) * @param outOfBoundsFactory - outofboundsfactory * @param interpolatorFactory - any interpolatorfactory * @param <T> type * @return transformed image */ public static < T extends RealType< T > > RandomAccessibleInterval< FloatType > transformView( final RandomAccessibleInterval< T > input, final AffineTransform3D transform, final Interval boundingBox, final OutOfBoundsFactory< T, RandomAccessible< T > > outOfBoundsFactory, final InterpolatorFactory< FloatType, RandomAccessible< FloatType > > interpolatorFactory ) { final long[] offset = new long[ input.numDimensions() ]; final long[] size = new long[ input.numDimensions() ]; for ( int d = 0; d < offset.length; ++d ) { offset[ d ] = boundingBox.min( d ); size[ d ] = boundingBox.dimension( d ); } final TransformedInputGeneralRandomAccessible< T > virtual = new TransformedInputGeneralRandomAccessible< T >( input, transform, outOfBoundsFactory, interpolatorFactory, offset ); return Views.interval( virtual, new FinalInterval( size ) ); }
public static void indexToPositionForInterval( long index, final Interval interval, final Positionable position ) { final int maxDim = interval.numDimensions() - 1; for ( int d = 0; d < maxDim; ++d ) { final long dim = interval.dimension( d ); final long j = index / dim; position.setPosition( index - j * dim + interval.min( d ), d ); index = j; } position.setPosition( index + interval.min( maxDim ), maxDim ); }
/** * 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 ); }
public static RandomAccessibleInterval< FloatType > transformBlending( final Interval inputImgInterval, final float[] border, final float[] blending, final AffineTransform3D transform, final Interval boundingBox ) { if ( inputImgInterval.dimension( 2 ) == 1 && inputImgInterval.min( 2 ) == 0 ) { final float[] border2d = new float[]{ border[ 0 ], border[ 1 ] }; final float[] blending2d = new float[]{ blending[ 0 ], blending[ 1 ] }; final long[] min = new long[]{ inputImgInterval.min( 0 ), inputImgInterval.min( 1 ) }; final long[] max = new long[]{ inputImgInterval.max( 0 ), inputImgInterval.max( 1 ) }; final BlendingRealRandomAccessible blend = new BlendingRealRandomAccessible( new FinalInterval( min, max ), border2d, blending2d ); return transformWeight( RealViews.addDimension( blend ), transform, boundingBox ); } else { return transformWeight( new BlendingRealRandomAccessible( new FinalInterval( inputImgInterval ), border, blending ), transform, boundingBox ); } }
/** * 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(); }
public static enum ImgDataType { VIRTUAL, CACHED, PRECOMPUTED }; public static String[] imgDataTypeChoice = new String[]{ "Virtual", "Cached", "Precompute Image" };
/** * View on interval of a source. If wanted, dims with size 1 are removed. * * @param src * The source {@link RandomAccessibleInterval} * @param interval * Interval */ public static final <T extends Type<T>> RandomAccessibleInterval<T> subsetView( final RandomAccessibleInterval<T> src, final Interval interval) { boolean oneSizedDims = false; for (int d = 0; d < interval.numDimensions(); d++) { if (interval.dimension(d) == 1) { oneSizedDims = true; break; } } if (intervalEquals(src, interval) && !oneSizedDims) return src; RandomAccessibleInterval<T> res; if (Intervals.contains(src, interval)) res = Views.offsetInterval(src, interval); else throw new IllegalArgumentException( "Interval must fit into src in SubsetViews.subsetView(...)"); for (int d = interval.numDimensions() - 1; d >= 0; --d) if (interval.dimension(d) == 1 && res.numDimensions() > 1) res = Views.hyperSlice(res, d, 0); return res; }
public static < T > RandomAccessibleInterval< T > constantRandomAccessibleInterval( final T constant, final Interval interval ) { return Views.interval( constantRandomAccessible( constant, interval.numDimensions() ), interval ); }
private long[] resultDims( final Interval src ) { long[] dims = new long[ src.numDimensions() ]; src.dimensions( dims ); return dims; }
public RectangleNeighborhoodLocalizableSampler( final RandomAccessibleInterval< T > source, final Interval span, final RectangleNeighborhoodFactory< T > factory ) { super( source ); this.source = source; this.span = span; neighborhoodFactory = factory; currentPos = new long[ n ]; currentMin = new long[ n ]; currentMax = new long[ n ]; final long[] accessMin = new long[ n ]; final long[] accessMax = new long[ n ]; source.min( accessMin ); source.max( accessMax ); for ( int d = 0; d < n; ++d ) { accessMin[ d ] += span.min( d ); accessMax[ d ] += span.max( d ); } currentNeighborhood = neighborhoodFactory.create( currentPos, currentMin, currentMax, span, source.randomAccess( new FinalInterval( accessMin, accessMax ) ) ); }
private static Interval initIntervals(final Interval src, final int[] axesOfInterest) { final long[] dimensionsToIterate = new long[src.numDimensions()]; src.dimensions(dimensionsToIterate); // determine axis to iterate for (int i = 0; i < src.numDimensions(); i++) { for (int j = 0; j < axesOfInterest.length; j++) { if (axesOfInterest[j] == i) { dimensionsToIterate[i] = 1; break; } } } return new FinalInterval(dimensionsToIterate); }