Search in sources :

Example 1 with SubsampleIntervalView

use of net.imglib2.view.SubsampleIntervalView in project imagej-ops by imagej.

the class SubsampleViewTest method testIntervalSubsampleSteps.

@Test
public void testIntervalSubsampleSteps() {
    Img<DoubleType> img = ArrayImgs.doubles(10, 10);
    Random r = new Random();
    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));
}
Also used : SubsampleIntervalView(net.imglib2.view.SubsampleIntervalView) Random(java.util.Random) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 2 with SubsampleIntervalView

use of net.imglib2.view.SubsampleIntervalView in project imagej-ops by imagej.

the class SubsampleViewTest method testIntervalSubsample.

@Test
public void testIntervalSubsample() {
    Img<DoubleType> img = ArrayImgs.doubles(10, 10);
    Random r = new Random();
    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));
}
Also used : SubsampleIntervalView(net.imglib2.view.SubsampleIntervalView) Random(java.util.Random) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Aggregations

Random (java.util.Random)2 AbstractOpTest (net.imagej.ops.AbstractOpTest)2 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)2 DoubleType (net.imglib2.type.numeric.real.DoubleType)2 SubsampleIntervalView (net.imglib2.view.SubsampleIntervalView)2 Test (org.junit.Test)2