Search in sources :

Example 41 with FinalInterval

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

Example 42 with FinalInterval

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

the class CreateImgTest method testImageMinimum.

@Test
public void testImageMinimum() {
    final Random randomGenerator = new Random();
    for (int i = 0; i < TEST_SIZE; i++) {
        // between 2 and 5 dimensions
        final long[] max = new long[randomGenerator.nextInt(4) + 2];
        final long[] min = new long[max.length];
        // between 2 and 10 pixels per dimensions
        for (int j = 0; j < max.length; j++) {
            max[j] = randomGenerator.nextInt(9) + 2;
            min[j] = Math.max(0, max[j] - randomGenerator.nextInt(4));
        }
        // create img
        final Img<?> img = (Img<?>) ops.run(CreateImgFromInterval.class, new FinalInterval(min, max));
        assertArrayEquals("Image Minimum:", min, Intervals.minAsLongArray(img));
        assertArrayEquals("Image Maximum:", max, Intervals.maxAsLongArray(img));
    }
}
Also used : CreateImgFromInterval(net.imagej.ops.create.img.CreateImgFromInterval) CreateImgFromImg(net.imagej.ops.create.img.CreateImgFromImg) Img(net.imglib2.img.Img) Random(java.util.Random) FinalInterval(net.imglib2.FinalInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

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