Search in sources :

Example 16 with ArrayImgFactory

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

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

the class CollapseViewTest method defaultCollapseTest.

@Test
public void defaultCollapseTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    CompositeIntervalView<DoubleType, ? extends GenericComposite<DoubleType>> il2 = Views.collapse(img);
    CompositeIntervalView<DoubleType, ? extends GenericComposite<DoubleType>> opr = ops.transform().collapseView(img);
    assertEquals(il2.numDimensions(), opr.numDimensions());
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 18 with ArrayImgFactory

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

the class ExtendRandomViewTest method extendRandomTest.

@Test
public void extendRandomTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    OutOfBounds<DoubleType> il2 = Views.extendRandom(img, 0, 0).randomAccess();
    OutOfBounds<DoubleType> opr = ops.transform().extendRandomView(img, 0, 0).randomAccess();
    il2.setPosition(new int[] { -1, -1 });
    opr.setPosition(new int[] { -1, -1 });
    assertEquals(il2.get().get(), opr.get().get(), 1e-10);
    il2.setPosition(new int[] { 11, 11 });
    opr.setPosition(new int[] { 11, 11 });
    assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 19 with ArrayImgFactory

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

the class ExtendValueViewTest method extendValueTest.

@Test
public void extendValueTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    OutOfBounds<DoubleType> il2 = Views.extendValue(img, new DoubleType(0)).randomAccess();
    OutOfBounds<DoubleType> opr = ops.transform().extendValueView(img, new DoubleType(0)).randomAccess();
    il2.setPosition(new int[] { -1, -1 });
    opr.setPosition(new int[] { -1, -1 });
    assertEquals(il2.get().get(), opr.get().get(), 1e-10);
    il2.setPosition(new int[] { 11, 11 });
    opr.setPosition(new int[] { 11, 11 });
    assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 20 with ArrayImgFactory

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

the class ConvolveTest method testConvolveMethodSelection.

/**
 * Tests that the correct convolver is selected when using a small kernel.
 */
@Test
public void testConvolveMethodSelection() {
    final Img<ByteType> in = new ArrayImgFactory<ByteType>().create(new int[] { 20, 20 }, new ByteType());
    // use a small kernel
    int[] kernelSize = new int[] { 3, 3 };
    Img<FloatType> kernel = new ArrayImgFactory<FloatType>().create(kernelSize, new FloatType());
    Op op = ops.op(Ops.Filter.Convolve.class, in, kernel);
    // we should get ConvolveNaive
    assertSame(ConvolveNaiveF.class, op.getClass());
    // make sure it runs
    @SuppressWarnings("unchecked") final Img<FloatType> out1 = (Img<FloatType>) ops.run(ConvolveNaiveF.class, in, kernel);
    assertEquals(out1.dimension(0), 20);
    // use a bigger kernel
    kernelSize = new int[] { 30, 30 };
    kernel = new ArrayImgFactory<FloatType>().create(kernelSize, new FloatType());
    op = ops.op(Ops.Filter.Convolve.class, in, kernel);
    // this time we should get ConvolveFFT
    assertSame(ConvolveFFTF.class, op.getClass());
    // make sure it runs
    @SuppressWarnings("unchecked") final Img<FloatType> out2 = (Img<FloatType>) ops.run(ConvolveFFTF.class, in, kernel);
    assertEquals(out2.dimension(0), 20);
}
Also used : Op(net.imagej.ops.Op) BinaryFunctionOp(net.imagej.ops.special.function.BinaryFunctionOp) UnaryFunctionOp(net.imagej.ops.special.function.UnaryFunctionOp) Img(net.imglib2.img.Img) ByteType(net.imglib2.type.numeric.integer.ByteType) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) FloatType(net.imglib2.type.numeric.real.FloatType) ComplexFloatType(net.imglib2.type.numeric.complex.ComplexFloatType) Ops(net.imagej.ops.Ops) 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