Search in sources :

Example 11 with ArrayImgFactory

use of net.imglib2.img.array.ArrayImgFactory 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 12 with ArrayImgFactory

use of net.imglib2.img.array.ArrayImgFactory 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 13 with ArrayImgFactory

use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.

the class StackViewTest method stackWithAccessModeTest.

@Test
public void stackWithAccessModeTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    List<Img<DoubleType>> list = new ArrayList<>();
    list.add(img);
    list.add(img);
    RandomAccessibleInterval<DoubleType> il2 = Views.stack(StackAccessMode.DEFAULT, list);
    RandomAccessibleInterval<DoubleType> opr = ops.transform().stackView(list, StackAccessMode.DEFAULT);
    assertEquals(il2.dimension(2), opr.dimension(2));
}
Also used : Img(net.imglib2.img.Img) DoubleType(net.imglib2.type.numeric.real.DoubleType) ArrayList(java.util.ArrayList) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 14 with ArrayImgFactory

use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.

the class SubsampleViewTest method defaultSubsampleStepsTest.

@Test
public void defaultSubsampleStepsTest() {
    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());
    }
    SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2, 1);
    SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2, 1);
    Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor();
    RandomAccess<DoubleType> oprRA = opr.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 15 with ArrayImgFactory

use of net.imglib2.img.array.ArrayImgFactory 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)

Aggregations

AbstractOpTest (net.imagej.ops.AbstractOpTest)52 Test (org.junit.Test)52 DoubleType (net.imglib2.type.numeric.real.DoubleType)47 Random (java.util.Random)14 Img (net.imglib2.img.Img)8 FinalInterval (net.imglib2.FinalInterval)7 ArrayImgFactory (net.imglib2.img.array.ArrayImgFactory)7 FloatType (net.imglib2.type.numeric.real.FloatType)6 FinalDimensions (net.imglib2.FinalDimensions)4 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)4 ArrayList (java.util.ArrayList)3 Dimensions (net.imglib2.Dimensions)3 Point (net.imglib2.Point)3 MixedTransformView (net.imglib2.view.MixedTransformView)3 Before (org.junit.Before)3 BinaryFunctionOp (net.imagej.ops.special.function.BinaryFunctionOp)2 UnaryFunctionOp (net.imagej.ops.special.function.UnaryFunctionOp)2 Interval (net.imglib2.Interval)2 ComplexFloatType (net.imglib2.type.numeric.complex.ComplexFloatType)2 ByteType (net.imglib2.type.numeric.integer.ByteType)2