/** * Sample only every <em>step</em><sup>th</sup> value of a source * {@link RandomAccessibleInterval}. This is effectively an integer scaling * and zero offset transformation. * * @param source * the source * @param step * the subsampling step size * @return a subsampled {@link RandomAccessibleInterval} with its origin * coordinates at zero */ public static < T > SubsampleIntervalView< T > subsample( final RandomAccessibleInterval< T > source, final long step ) { return new SubsampleIntervalView<>( source, step ); }
@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)); } }
@Test public void testIntervalSubsample() { 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); SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2); Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 4 }).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)); }
/** * Sample only every <em>step</em><sup>th</sup> value of a source * {@link RandomAccessibleInterval}. This is effectively an integer scaling * and zero offset transformation. * * @param source * the source * @param step * the subsampling step size * @return a subsampled {@link RandomAccessibleInterval} with its origin * coordinates at zero */ public static < T > SubsampleIntervalView< T > subsample( final RandomAccessibleInterval< T > source, final long step ) { return new SubsampleIntervalView<>( source, step ); }
/** * Sample only every <em>step<sub>d</sub></em><sup>th</sup> value of a * source {@link RandomAccessibleInterval}. This is effectively an integer * scaling and zero offset transformation. * * @param source * the source * @param steps * the subsampling step sizes * @return a subsampled {@link RandomAccessibleInterval} with its origin * coordinates at zero */ public static < T > SubsampleIntervalView< T > subsample( final RandomAccessibleInterval< T > source, final long... steps ) { assert steps.length >= source.numDimensions(): "Dimensions do not match."; return new SubsampleIntervalView<>( source, steps ); }
/** * Sample only every <em>step<sub>d</sub></em><sup>th</sup> value of a * source {@link RandomAccessibleInterval}. This is effectively an integer * scaling and zero offset transformation. * * @param source * the source * @param steps * the subsampling step sizes * @return a subsampled {@link RandomAccessibleInterval} with its origin * coordinates at zero */ public static < T > SubsampleIntervalView< T > subsample( final RandomAccessibleInterval< T > source, final long... steps ) { assert steps.length >= source.numDimensions(): "Dimensions do not match."; return new SubsampleIntervalView<>( source, steps ); }