Search in sources :

Example 31 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class PermuteViewTest method testIntervalPermuteInverseCoordinates.

@Test
public void testIntervalPermuteInverseCoordinates() {
    Img<DoubleType> img = ArrayImgs.doubles(2, 2);
    Cursor<DoubleType> c = img.cursor();
    Random r = new Random();
    while (c.hasNext()) {
        c.next().set(r.nextDouble());
    }
    IntervalView<DoubleType> expected = Views.permuteCoordinatesInverse(img, new int[] { 0, 1 });
    Cursor<DoubleType> e = expected.cursor();
    RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[] { 0, 1 });
    RandomAccess<DoubleType> actualRA = actual.randomAccess();
    while (e.hasNext()) {
        e.next();
        actualRA.setPosition(e);
        assertEquals(e.get().get(), actualRA.get().get(), 1e-10);
    }
    assertTrue(Intervals.equals(expected, actual));
}
Also used : Random(java.util.Random) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 32 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class RasterViewTest method defaultRasterTest.

@Test
public void defaultRasterTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    Random r = new Random();
    for (DoubleType d : img) {
        d.set(r.nextDouble());
    }
    RealRandomAccessible<DoubleType> realImg = Views.interpolate(img, new FloorInterpolatorFactory<DoubleType>());
    RandomAccessibleOnRealRandomAccessible<DoubleType> il2 = Views.raster(realImg);
    RandomAccessibleOnRealRandomAccessible<DoubleType> opr = ops.transform().rasterView(realImg);
    Cursor<DoubleType> il2C = Views.interval(il2, img).localizingCursor();
    RandomAccess<DoubleType> oprRA = Views.interval(opr, img).randomAccess();
    while (il2C.hasNext()) {
        il2C.next();
        oprRA.setPosition(il2C);
        assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
    }
}
Also used : Random(java.util.Random) DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 33 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class ShearViewTest method ShearIntervalTest.

/**
 * Tests {@link ShearViewInterval}.
 */
@Test
public void ShearIntervalTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
    Cursor<DoubleType> imgC = img.cursor();
    while (imgC.hasNext()) {
        imgC.next().set(1);
    }
    Cursor<DoubleType> il2 = Views.shear(Views.extendZero(img), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1).cursor();
    RandomAccess<DoubleType> opr = ops.transform().shearView(Views.extendZero(img), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1).randomAccess();
    while (il2.hasNext()) {
        il2.next();
        opr.setPosition(il2);
        assertEquals(il2.get().get(), opr.get().get(), 1e-10);
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalInterval(net.imglib2.FinalInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 34 with Cursor

use of net.imglib2.Cursor in project imagej-ops by imagej.

the class ShearViewTest method defaultShearTest.

/**
 * Tests {@link DefaultShearView}.
 */
@Test
public void defaultShearTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
    Cursor<DoubleType> imgC = img.cursor();
    while (imgC.hasNext()) {
        imgC.next().set(1);
    }
    TransformView<DoubleType> il2 = Views.shear(Views.extendZero(img), 0, 1);
    TransformView<DoubleType> opr = ops.transform().shearView(Views.extendZero(img), 0, 1);
    Cursor<DoubleType> il2C = Views.interval(il2, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })).cursor();
    RandomAccess<DoubleType> oprRA = Views.interval(opr, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })).randomAccess();
    while (il2C.hasNext()) {
        il2C.next();
        oprRA.setPosition(il2C);
        assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalInterval(net.imglib2.FinalInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 35 with Cursor

use of net.imglib2.Cursor 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)

Aggregations

Test (org.junit.Test)43 AbstractOpTest (net.imagej.ops.AbstractOpTest)40 DoubleType (net.imglib2.type.numeric.real.DoubleType)30 Random (java.util.Random)21 FinalInterval (net.imglib2.FinalInterval)21 ByteType (net.imglib2.type.numeric.integer.ByteType)14 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)12 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)11 ArrayList (java.util.ArrayList)10 DiamondShape (net.imglib2.algorithm.neighborhood.DiamondShape)10 Shape (net.imglib2.algorithm.neighborhood.Shape)10 BitType (net.imglib2.type.logic.BitType)8 FloatType (net.imglib2.type.numeric.real.FloatType)8 Img (net.imglib2.img.Img)7 HorizontalLineShape (net.imglib2.algorithm.neighborhood.HorizontalLineShape)6 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)6 Before (org.junit.Before)6 IterableInterval (net.imglib2.IterableInterval)4 Point (net.imglib2.Point)4 RealPoint (net.imglib2.RealPoint)4