Search in sources :

Example 86 with Cursor

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

the class CopyImgLabelingTest method createData.

@SuppressWarnings("unchecked")
@Before
public void createData() {
    input = (ImgLabeling<String, IntType>) ops.run(DefaultCreateImgLabeling.class, new long[] { 10, 10 }, new IntType());
    final Cursor<LabelingType<String>> inc = input.cursor();
    while (inc.hasNext()) {
        inc.next().add(Math.random() > 0.5 ? "A" : "B");
    }
    // and another loop to construct some ABs
    while (inc.hasNext()) {
        inc.next().add(Math.random() > 0.5 ? "A" : "B");
    }
}
Also used : IntType(net.imglib2.type.numeric.integer.IntType) LabelingType(net.imglib2.roi.labeling.LabelingType) Before(org.junit.Before)

Example 87 with Cursor

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

Test (org.junit.Test)44 AbstractOpTest (net.imagej.ops.AbstractOpTest)40 DoubleType (net.imglib2.type.numeric.real.DoubleType)32 Random (java.util.Random)21 FinalInterval (net.imglib2.FinalInterval)21 ByteType (net.imglib2.type.numeric.integer.ByteType)14 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)12 ArrayList (java.util.ArrayList)11 RectangleShape (net.imglib2.algorithm.neighborhood.RectangleShape)11 DiamondShape (net.imglib2.algorithm.neighborhood.DiamondShape)10 Shape (net.imglib2.algorithm.neighborhood.Shape)10 BitType (net.imglib2.type.logic.BitType)8 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)8 FloatType (net.imglib2.type.numeric.real.FloatType)8 Img (net.imglib2.img.Img)7 HorizontalLineShape (net.imglib2.algorithm.neighborhood.HorizontalLineShape)6 Before (org.junit.Before)6 Point (net.imglib2.Point)4 RealPoint (net.imglib2.RealPoint)4 Neighborhood (net.imglib2.algorithm.neighborhood.Neighborhood)4