Refine search
/** * Creates an image with randomized content. * @param type Pixel type * @param interval Interval */ public < T extends NativeType< T > > RandomAccessibleInterval< T > nextImage( final T type, Interval interval ) { long[] sizes = Intervals.dimensionsAsLongArray( interval ); long[] min = Intervals.minAsLongArray( interval ); return Views.translate( nextImage( type, sizes ), min ); }
@Override public boolean conforms() { // conforms only if the kernel is sufficiently small return Intervals.numElements(kernel) <= 9; }
private static Interval slightlyEnlarge(RealInterval realInterval, long border) { return Intervals.expand(Intervals.smallestContainingInterval(realInterval), border); }
static String intervalToString( Interval a ) { return "{min=" + Arrays.toString( Intervals.minAsLongArray( a ) ) + ", max=" + Arrays.toString( Intervals.maxAsLongArray( a ) ) + "}"; }
@Override public RandomAccessibleInterval<T> calculate(RandomAccessibleInterval<T> input) { final long[] newDims = Intervals.dimensionsAsLongArray(in()); for (int i = 0; i < Math.min(scaleFactors.length, in().numDimensions()); i++) { newDims[i] = Math.round(in().dimension(i) * scaleFactors[i]); } IntervalView<T> interval = Views.interval(Views.raster(RealViews.affineReal( Views.interpolate(Views.extendMirrorSingle(input), interpolator), new Scale(scaleFactors))), new FinalInterval(newDims)); return interval; }
/** * 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 ); } }
final Interval interval = Intervals.createMinSize( minsize ); final IntervalView< T > view = Views.zeroMin(Views.interval( Views.extendZero( img ), interval ) ); final RandomAccess< T > sourceRA = view.randomAccess( view ); final Cursor< T > targetCursor = crop.localizingCursor();
/** * Expand a RandomAccessibleInterval as specified by border. Out of bounds * pixels will be sampled by mirroring source. Boundary pixels are not * repeated. Note that this requires that all dimensions of the source (F * source) must be > 1. * * @param source * the interval to expand. * @return Expansion of the {@link RandomAccessibleInterval} source as * specified by border. */ public static < T > IntervalView< T > expandMirrorSingle( final RandomAccessibleInterval< T > source, final long... border ) { return interval( extendMirrorSingle( source ), Intervals.expand( source, border ) ); }
final Interval cropBoundingBox = Intervals.smallestContainingInterval( IntervalBoundingBox.getBoundingBox( sourceCorners ) ); Interval sourceInterval = Intervals.intersect( cropBoundingBox, sourceImg ); if ( Intervals.isEmpty( sourceInterval ) ) minsize[ d ] = cropBoundingBox.min( d ) + cropBoundingBox.dimension( d ) / 2; Arrays.fill( minsize, n, n * 2, 1 ); sourceInterval = Intervals.createMinSize( minsize ); croppedSourceImg = Views.zeroMin( Views.interval( Views.extendBorder( sourceImg ), sourceInterval ) ); croppedSourceTransform.set( 1, 0, 0, sourceInterval.min( 0 ),
/** * Expand a RandomAccessibleInterval as specified by border. source will be * extended with a periodic out-of-bounds strategy. * * @param source * the interval to expand. * @return Expansion of the {@link RandomAccessibleInterval} source as * specified by border. */ public static < T > IntervalView< T > expandPeriodic( final RandomAccessibleInterval< T > source, final long... border ) { return interval( extendPeriodic( source ), Intervals.expand( source, border ) ); }
/** * Expand a RandomAccessibleInterval as specified by border. source will be * extended with the zero-element of that data type. * * @param source * the interval to expand. * @return Expansion of the {@link RandomAccessibleInterval} source as * specified by border. */ public static < T extends NumericType< T > > IntervalView< T > expandZero( final RandomAccessibleInterval< T > source, final long... border ) { return interval( extendZero( source ), Intervals.expand( source, border ) ); }
/** * Expand a RandomAccessibleInterval as specified by border. source will be * extended with the border value. * * @param source * the interval to expand. * @return Expansion of the {@link RandomAccessibleInterval} source as * specified by border. */ public static < T > IntervalView< T > expandBorder( final RandomAccessibleInterval< T > source, final long... border ) { return interval( extendBorder( source ), Intervals.expand( source, border ) ); }
/** * 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 result * output image * @param dimension * along which dimension the partial derivatives are computed */ public static < T extends NumericType< T > > void gradientCentralDifference( final RandomAccessible< T > source, final RandomAccessibleInterval< T > result, final int dimension ) { final RandomAccessibleInterval< T > back = Views.interval( source, Intervals.translate( result, -1, dimension ) ); final RandomAccessibleInterval< T > front = Views.interval( source, Intervals.translate( result, 1, dimension ) ); LoopBuilder.setImages( result, back, front ).forEachPixel( ( r, b, f ) -> { r.set( f ); r.sub( b ); r.mul( 0.5 ); } ); }
/** * Expand a RandomAccessibleInterval as specified by border. Out of bounds * pixels will be sampled by mirroring source. Boundary pixels are repeated. * * @param source * the interval to expand. * @return Expansion of the {@link RandomAccessibleInterval} source as * specified by border. */ public static < T > IntervalView< T > expandMirrorDouble( final RandomAccessibleInterval< T > source, final long... border ) { return interval( extendMirrorDouble( source ), Intervals.expand( source, border ) ); }
private static <V> RandomAccessibleInterval<V> trim( final RandomAccessibleInterval<V> image, final int[] blockSize) { final long[] min = Intervals.minAsLongArray(image); final long[] max = Intervals.maxAsLongArray(image); for (int d = 0; d < blockSize.length; d++) { final long trimSize = image.dimension(d) % blockSize[d]; final long half = trimSize / 2; min[d] += half; max[d] -= trimSize - half; } return Views.interval(image, min, max); } }
/** * Translate the source view by the given translation vector. Pixel * <em>x</em> in the source view has coordinates <em>(x + translation)</em> * in the resulting view. * * @param interval * the source * @param translation * translation vector of the source view. The pixel at <em>x</em> * in the source view becomes <em>(x + translation)</em> in the * resulting view. */ public static < T > IntervalView< T > translate( final RandomAccessibleInterval< T > interval, final long... translation ) { return Views.interval( Views.translate( ( RandomAccessible< T > ) interval, translation ), Intervals.translate( interval, translation ) ); }
private static < T extends ValueEquals< T > > void testEqual( final RandomAccessibleInterval< T > rai1, final RandomAccessibleInterval< T > rai2 ) { Assert.assertArrayEquals( Intervals.minAsLongArray( rai1 ), Intervals.minAsLongArray( rai2 ) ); Assert.assertArrayEquals( Intervals.maxAsLongArray( rai1 ), Intervals.maxAsLongArray( rai2 ) ); for ( final Pair< T, T > p : Views.interval( Views.pair( rai1, rai2 ), rai1 ) ) Assert.assertTrue( p.getA().valueEquals( p.getB() ) ); }
/** * Checks if both images have equal intervals and content. * A predicate must be given to check if two pixels are equal. */ public static < T, U > boolean imagesEqual( final RandomAccessibleInterval< ? extends T > a, final RandomAccessibleInterval< ? extends U > b, final BiPredicate< T, U > pixelEquals ) { if ( !Intervals.equals( a, b ) ) return false; for ( final Pair< ? extends T, ? extends U > pair : Views.interval( Views.pair( a, b ), b ) ) if ( !pixelEquals.test( pair.getA(), pair.getB() ) ) return false; return true; }
@Test public void testIntervalSubsampleSteps() { Img<DoubleType> img = ArrayImgs.doubles(10,10); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } SubsampleIntervalView<DoubleType> expected = Views.subsample((RandomAccessibleInterval<DoubleType>) img, 2, 1); SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2, 1); Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor(); RandomAccess<DoubleType> oprRA = actual.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } assertTrue(Intervals.equals(expected, actual)); } }