Search in sources :

Example 56 with ArrayImgFactory

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

the class TranslateViewTest method defaultTranslateTest.

@Test
public void defaultTranslateTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    MixedTransformView<DoubleType> il2 = Views.translate(deinterval(img), 2, 5);
    MixedTransformView<DoubleType> opr = ops.transform().translateView(deinterval(img), 2, 5);
    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 57 with ArrayImgFactory

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

the class ZeroMinViewTest method defaultZeroMinTest.

@Test
public void defaultZeroMinTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
    IntervalView<DoubleType> imgTranslated = Views.interval(Views.translate((RandomAccessible<DoubleType>) img, 2, 5), new long[] { 2, 5 }, new long[] { 12, 15 });
    IntervalView<DoubleType> il2 = Views.zeroMin(imgTranslated);
    IntervalView<DoubleType> opr = ops.transform().zeroMinView(imgTranslated);
    assertTrue(Views.isZeroMin(il2) == Views.isZeroMin(opr));
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) RandomAccessible(net.imglib2.RandomAccessible) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 58 with ArrayImgFactory

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

the class CreateLabelingTest method testImageFactory.

@SuppressWarnings("unchecked")
@Test
public void testImageFactory() {
    final Dimensions dim = new FinalDimensions(10, 10, 10);
    assertEquals("Labeling Factory: ", ArrayImgFactory.class, ((Img<?>) ((ImgLabeling<String, ?>) ops.run(DefaultCreateImgLabeling.class, dim, null, new ArrayImgFactory<IntType>())).getIndexImg()).factory().getClass());
    assertEquals("Labeling Factory: ", CellImgFactory.class, ((Img<?>) ((ImgLabeling<String, ?>) ops.run(DefaultCreateImgLabeling.class, dim, null, new CellImgFactory<IntType>())).getIndexImg()).factory().getClass());
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) Img(net.imglib2.img.Img) Dimensions(net.imglib2.Dimensions) FinalDimensions(net.imglib2.FinalDimensions) IntType(net.imglib2.type.numeric.integer.IntType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 59 with ArrayImgFactory

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

the class CopyRAITest method createData.

@Before
public void createData() {
    input = new ArrayImgFactory<UnsignedByteType>().create(new int[] { 120, 100 }, new UnsignedByteType());
    final Random r = new Random(System.currentTimeMillis());
    final Cursor<UnsignedByteType> inc = input.cursor();
    while (inc.hasNext()) {
        inc.next().setReal(r.nextDouble() * 255);
    }
    // create
    final long[] start = new long[] { 16, 16, 16 };
    final long[] end = new long[] { 47, 47, 47 };
    // create an input with a cube at the center
    input2 = ops.create().img(new FinalDimensions(size1), new UnsignedByteType());
    // create the same input but force it to be a planar image
    inputPlanar = ops.create().img(new FinalDimensions(size1), new UnsignedByteType(), new PlanarImgFactory<UnsignedByteType>());
    // get centered views
    view = Views.interval(input2, new FinalInterval(start, end));
    viewPlanar = Views.interval(inputPlanar, new FinalInterval(start, end));
    final Cursor<UnsignedByteType> cursor = view.cursor();
    final Cursor<UnsignedByteType> cursorPlanar = viewPlanar.cursor();
    // set every pixel in the view to 100
    while (cursor.hasNext()) {
        cursor.fwd();
        cursorPlanar.fwd();
        cursor.get().setReal(100.0);
        cursorPlanar.get().setReal(100.0);
    }
}
Also used : FinalDimensions(net.imglib2.FinalDimensions) Random(java.util.Random) PlanarImgFactory(net.imglib2.img.planar.PlanarImgFactory) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) FinalInterval(net.imglib2.FinalInterval) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory) Before(org.junit.Before)

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