/** * Sample only every <em>step</em><sup>th</sup> value of a source * {@link RandomAccessible}. This is effectively an integer scaling * transformation. * * @param source * the source * @param step * the subsampling step size * @return a subsampled {@link RandomAccessible} * */ public static < T > SubsampleView< T > subsample( final RandomAccessible< T > source, final long step ) { return new SubsampleView<>( source, step ); }
@Test public void defaultSubsampleStepsTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2, 1); SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2, 1); Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor(); RandomAccess<DoubleType> oprRA = opr.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } }
@Test public void defaultSubsampleTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2); SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2); Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 4 }).localizingCursor(); RandomAccess<DoubleType> oprRA = opr.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } }
/** * Sample only every <em>step</em><sup>th</sup> value of a source * {@link RandomAccessible}. This is effectively an integer scaling * transformation. * * @param source * the source * @param step * the subsampling step size * @return a subsampled {@link RandomAccessible} * */ public static < T > SubsampleView< T > subsample( final RandomAccessible< T > source, final long step ) { return new SubsampleView<>( source, step ); }
/** * Sample only every <em>step<sub>d</sub></em><sup>th</sup> value of a * source {@link RandomAccessible}. This is effectively an integer scaling * transformation. * * @param source * the source * @param steps * the subsampling step sizes * @return a subsampled {@link RandomAccessible} * */ public static < T > SubsampleView< T > subsample( final RandomAccessible< T > source, final long... steps ) { assert steps.length >= source.numDimensions(): "Dimensions do not match."; return new SubsampleView<>( source, steps ); }
/** * Sample only every <em>step<sub>d</sub></em><sup>th</sup> value of a * source {@link RandomAccessible}. This is effectively an integer scaling * transformation. * * @param source * the source * @param steps * the subsampling step sizes * @return a subsampled {@link RandomAccessible} * */ public static < T > SubsampleView< T > subsample( final RandomAccessible< T > source, final long... steps ) { assert steps.length >= source.numDimensions(): "Dimensions do not match."; return new SubsampleView<>( source, steps ); }