Search in sources :

Example 46 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType 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 47 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType 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 48 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.

the class RotateViewTest method testDefaultRotate.

@Test
public void testDefaultRotate() {
    final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 20, 10 }, new DoubleType());
    final MixedTransformView<DoubleType> il2 = Views.rotate((RandomAccessible<DoubleType>) img, 1, 0);
    final MixedTransformView<DoubleType> opr = ops.transform().rotateView(deinterval(img), 1, 0);
    for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) {
        for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) {
            assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j], 1e-10);
        }
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 49 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType 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 50 with DoubleType

use of net.imglib2.type.numeric.real.DoubleType 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)

Aggregations

DoubleType (net.imglib2.type.numeric.real.DoubleType)142 Test (org.junit.Test)114 AbstractOpTest (net.imagej.ops.AbstractOpTest)104 LongType (net.imglib2.type.numeric.integer.LongType)37 Random (java.util.Random)19 Img (net.imglib2.img.Img)9 FinalInterval (net.imglib2.FinalInterval)8 ArrayList (java.util.ArrayList)7 Ops (net.imagej.ops.Ops)7 BitType (net.imglib2.type.logic.BitType)7 UnaryComputerOp (net.imagej.ops.special.computer.UnaryComputerOp)6 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)6 RealLocalizable (net.imglib2.RealLocalizable)6 LocalThresholdMethod (net.imagej.ops.threshold.LocalThresholdMethod)5 FinalDimensions (net.imglib2.FinalDimensions)5 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)4 Dimensions (net.imglib2.Dimensions)4 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)4 Module (org.scijava.module.Module)4 CreateImgFromDimsAndType (net.imagej.ops.create.img.CreateImgFromDimsAndType)3