Search in sources :

Example 26 with Cursor

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

the class IntervalViewTest method defaultIntervalTest.

@Test
public void defaultIntervalTest() {
    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());
    }
    Cursor<DoubleType> il2 = Views.interval(img, img).localizingCursor();
    RandomAccess<DoubleType> opr = ops.transform().intervalView(img, img).randomAccess();
    while (il2.hasNext()) {
        DoubleType e = il2.next();
        opr.setPosition(il2);
        assertEquals(e.get(), opr.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 27 with Cursor

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

the class PermuteViewTest method testIntervalPermuteCoordinates.

@Test
public void testIntervalPermuteCoordinates() {
    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.permuteCoordinates(img, new int[] { 0, 1 });
    Cursor<DoubleType> e = expected.cursor();
    RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesView(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 28 with Cursor

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

the class PermuteViewTest method testIntervalPermuteInverseDimensionCoordinates.

@Test
public void testIntervalPermuteInverseDimensionCoordinates() {
    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.permuteCoordinateInverse(img, new int[] { 0, 1 }, 1);
    Cursor<DoubleType> e = expected.cursor();
    RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[] { 0, 1 }, 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 29 with Cursor

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

the class PermuteViewTest method permuteCoordinatesInverseOfDimensionTest.

@Test
public void permuteCoordinatesInverseOfDimensionTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
    Cursor<DoubleType> c = img.cursor();
    Random r = new Random();
    while (c.hasNext()) {
        c.next().set(r.nextDouble());
    }
    IntervalView<DoubleType> out = Views.permuteCoordinateInverse(img, new int[] { 0, 1 }, 1);
    Cursor<DoubleType> il2 = out.cursor();
    RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[] { 0, 1 }, 1).randomAccess();
    while (il2.hasNext()) {
        il2.next();
        opr.setPosition(il2);
        assertEquals(il2.get().get(), opr.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 30 with Cursor

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

the class PermuteViewTest method testIntervalPermuteDimensionCoordinates.

@Test
public void testIntervalPermuteDimensionCoordinates() {
    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.permuteCoordinates(img, new int[] { 0, 1 }, 1);
    Cursor<DoubleType> e = expected.cursor();
    RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesView(img, new int[] { 0, 1 }, 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)

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