Search in sources :

Example 16 with FinalInterval

use of net.imglib2.FinalInterval 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 17 with FinalInterval

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

the class UnshearViewTest method defaultUnshearTest.

@Test
public void defaultUnshearTest() {
    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.unshear(Views.shear(Views.extendZero(img), 0, 1), 0, 1);
    TransformView<DoubleType> opr = ops.transform().unshearView(Views.shear(Views.extendZero(img), 0, 1), 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 18 with FinalInterval

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

the class UnshearViewTest method UnshearIntervalTest.

@Test
public void UnshearIntervalTest() {
    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.unshear(Views.shear(Views.extendZero(img), 0, 1), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1).cursor();
    RandomAccess<DoubleType> opr = ops.transform().unshearView(Views.shear(Views.extendZero(img), 0, 1), 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 19 with FinalInterval

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

the class CropTest method testCropTypes.

/**
 * Verifies that the types of the objects returned are correct.
 */
@Test
public void testCropTypes() {
    // Set-up interval
    final Interval defInterval = new FinalInterval(new long[] { 0, 0, 0 }, new long[] { 19, 19, 19 });
    final Interval smallerInterval = new FinalInterval(new long[] { 0, 0, 0 }, new long[] { 19, 19, 18 });
    // check if result is ImgView
    assertTrue(ops.run(CropRAI.class, in, defInterval) instanceof Img);
    // check if result is ImgPlus
    final Object imgPlus = ops.run(CropImgPlus.class, new ImgPlus<>(in), defInterval);
    assertTrue(imgPlus instanceof ImgPlus);
    // check if result is RandomAccessibleInterval
    final Object run = ops.run(CropRAI.class, Views.interval(in, smallerInterval), smallerInterval);
    assertTrue(run instanceof RandomAccessibleInterval && !(run instanceof Img));
}
Also used : Img(net.imglib2.img.Img) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) ImgPlus(net.imagej.ImgPlus) FinalInterval(net.imglib2.FinalInterval) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Interval(net.imglib2.Interval) FinalInterval(net.imglib2.FinalInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 20 with FinalInterval

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

the class AbstractOpTest method generateUnsignedVariableBitLengthTypeArrayTestImg.

public ArrayImg<UnsignedVariableBitLengthType, LongArray> generateUnsignedVariableBitLengthTypeArrayTestImg(final boolean fill, final int nbits, final long... dims) {
    final long[] array = new long[(int) Intervals.numElements(new FinalInterval(dims))];
    if (fill) {
        seed = 17;
        for (int i = 0; i < array.length; i++) {
            array[i] = (long) (((pseudoRandom() / Integer.MAX_VALUE)) % (Math.pow(2, nbits)));
        }
    }
    final LongArray l = new LongArray(array);
    return ArrayImgs.unsignedVariableBitLengths(l, nbits, dims);
}
Also used : LongArray(net.imglib2.img.basictypeaccess.array.LongArray) FinalInterval(net.imglib2.FinalInterval)

Aggregations

FinalInterval (net.imglib2.FinalInterval)41 AbstractOpTest (net.imagej.ops.AbstractOpTest)13 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)13 Test (org.junit.Test)13 DoubleType (net.imglib2.type.numeric.real.DoubleType)9 Img (net.imglib2.img.Img)7 BitType (net.imglib2.type.logic.BitType)7 Interval (net.imglib2.Interval)5 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)5 FloatType (net.imglib2.type.numeric.real.FloatType)4 ImgPlus (net.imagej.ImgPlus)3 RealType (net.imglib2.type.numeric.RealType)3 ByteType (net.imglib2.type.numeric.integer.ByteType)3 File (java.io.File)2 Random (java.util.Random)2 Dataset (net.imagej.Dataset)2 CreateImgFromImg (net.imagej.ops.create.img.CreateImgFromImg)2 DefaultMesh (net.imagej.ops.geom.geom3d.mesh.DefaultMesh)2 TriangularFacet (net.imagej.ops.geom.geom3d.mesh.TriangularFacet)2 FinalDimensions (net.imglib2.FinalDimensions)2