Search in sources :

Example 26 with FinalInterval

use of net.imglib2.FinalInterval in project vcell by virtualcell.

the class ImageStatsForPlotting method computeMean.

/**
 * Computes the mean of each XY slice along the 3rd dimension
 * TODO: Currently assumes only 3 dimensions, must handle time series of z stacks and multiple channels
 * @param data
 * @return Pair containing A) the 3rd dimension index, and B) the mean value of the XY slice
 */
private Pair<double[], double[]> computeMean(RandomAccessibleInterval<T> data, IterableInterval<BitType> mask) {
    double[] indices = new double[(int) data.dimension(2)];
    double[] means = new double[indices.length];
    for (int z = 0; z < indices.length; z++) {
        FinalInterval interval = Intervals.createMinMax(0, 0, z, data.dimension(0) - 1, data.dimension(1) - 1, z);
        double mean = 0.0;
        RandomAccessibleInterval<T> cropped = ops.transform().crop(data, interval);
        if (mask == null) {
            mean = ops.stats().mean(Views.iterable(cropped)).getRealDouble();
        } else {
            Cursor<BitType> maskCursor = mask.localizingCursor();
            RandomAccess<T> dataRA = cropped.randomAccess();
            RealSum sum = new RealSum();
            int size = 0;
            maskCursor.reset();
            while (maskCursor.hasNext()) {
                maskCursor.fwd();
                if (maskCursor.get().get()) {
                    dataRA.setPosition(maskCursor);
                    sum.add(dataRA.get().getRealDouble());
                    size++;
                }
            }
            mean = sum.getSum() / size;
        }
        indices[z] = z;
        means[z] = mean;
    }
    return new ValuePair<double[], double[]>(indices, means);
}
Also used : BitType(net.imglib2.type.logic.BitType) ValuePair(net.imglib2.util.ValuePair) FinalInterval(net.imglib2.FinalInterval) RealSum(net.imglib2.util.RealSum)

Example 27 with FinalInterval

use of net.imglib2.FinalInterval in project vcell by virtualcell.

the class LargestRegionSlice method run.

@Override
public void run() {
    int maxArea = 0;
    int zOfMaxArea = 0;
    for (int z = 0; z < data.dimension(2); z++) {
        FinalInterval interval = Intervals.createMinMax(0, 0, z, data.dimension(0) - 1, data.dimension(1) - 1, z);
        RandomAccessibleInterval<BitType> croppedRAI = ops.transform().crop(data, interval);
        IterableInterval<BitType> croppedII = Views.iterable(croppedRAI);
        Cursor<BitType> cursor = croppedII.cursor();
        int area = 0;
        while (cursor.hasNext()) {
            if (cursor.next().get()) {
                area++;
            }
        }
        if (area > maxArea) {
            maxArea = area;
            zOfMaxArea = z;
        }
    }
    FinalInterval interval = Intervals.createMinMax(0, 0, zOfMaxArea, data.dimension(0) - 1, data.dimension(1) - 1, zOfMaxArea);
    output = ops.transform().crop(data, interval);
}
Also used : BitType(net.imglib2.type.logic.BitType) FinalInterval(net.imglib2.FinalInterval)

Example 28 with FinalInterval

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

the class IntegralImgTest method testIntegralImageSimilarity.

/**
 * @see DefaultIntegralImg
 * @see SquareIntegralImg
 */
@SuppressWarnings({ "unchecked" })
@Test
public void testIntegralImageSimilarity() {
    RandomAccessibleInterval<LongType> out1 = (RandomAccessibleInterval<LongType>) ops.run(DefaultIntegralImg.class, in);
    RandomAccessibleInterval<DoubleType> out2 = (RandomAccessibleInterval<DoubleType>) ops.run(WrappedIntegralImg.class, in);
    // Remove 0s from integralImg by shifting its interval by +1
    final long[] min = new long[out2.numDimensions()];
    final long[] max = new long[out2.numDimensions()];
    for (int d = 0; d < out2.numDimensions(); ++d) {
        min[d] = out2.min(d) + 1;
        max[d] = out2.max(d);
    }
    // Define the Interval on the infinite random accessibles
    final FinalInterval interval = new FinalInterval(min, max);
    LocalThresholdTest.testIterableIntervalSimilarity(Views.iterable(out1), Views.iterable(Views.offsetInterval(out2, interval)));
}
Also used : LongType(net.imglib2.type.numeric.integer.LongType) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalInterval(net.imglib2.FinalInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test) LocalThresholdTest(net.imagej.ops.threshold.apply.LocalThresholdTest)

Example 29 with FinalInterval

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

the class SliceTest method testNonZeroMinimumInterval.

@Test
public void testNonZeroMinimumInterval() {
    Img<ByteType> img3D = ArrayImgs.bytes(50, 50, 3);
    IntervalView<ByteType> interval2D = Views.interval(img3D, new FinalInterval(new long[] { 25, 25, 2 }, new long[] { 35, 35, 2 }));
    final int[] xyAxis = new int[] { 0, 1 };
    // iterate through every slice, should return a single
    // RandomAccessibleInterval<?> from 25, 25, 2 to 35, 35, 2
    final SlicesII<ByteType> hyperSlices = new SlicesII<>(interval2D, xyAxis, true);
    final Cursor<RandomAccessibleInterval<ByteType>> c = hyperSlices.cursor();
    int i = 0;
    while (c.hasNext()) {
        c.next();
        i++;
    }
    assertEquals(1, i);
}
Also used : RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) FinalInterval(net.imglib2.FinalInterval) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType) ByteType(net.imglib2.type.numeric.integer.ByteType) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 30 with FinalInterval

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

the class DefaultMarchingCubes method calculate.

@SuppressWarnings({ "unchecked" })
@Override
public DefaultMesh calculate(final RandomAccessibleInterval<T> input) {
    DefaultMesh output = new DefaultMesh();
    ExtendedRandomAccessibleInterval<T, RandomAccessibleInterval<T>> extended = Views.extendValue(input, (T) new BoolType(false));
    Cursor<T> c = Views.interval(extended, new FinalInterval(new long[] { input.min(0) - 1, input.min(1) - 1, input.min(2) - 1 }, new long[] { input.max(0) + 1, input.max(1) + 1, input.max(2) + 1 })).localizingCursor();
    while (c.hasNext()) {
        c.next();
        int cursorX = c.getIntPosition(0);
        int cursorY = c.getIntPosition(1);
        int cursorZ = c.getIntPosition(2);
        Cursor<T> cu = getCube(extended, cursorX, cursorY, cursorZ);
        int i = 0;
        double[] vertex_values = new double[8];
        while (cu.hasNext()) {
            vertex_values[i++] = (cu.next().get()) ? 1 : 0;
        }
        // 6------7
        // /| /|
        // 2-----3 |
        // | 4---|-5
        // |/ |/
        // 0-----1
        vertex_values = mapFlatIterableToLookUpCube(vertex_values);
        // 4------5
        // /| /|
        // 7-----6 |
        // | 0---|-1
        // |/ |/
        // 3-----2
        int cubeindex = getCubeIndex(vertex_values);
        if (EDGE_TABLE[cubeindex] != 0) {
            int[] p0 = new int[] { 0 + cursorX, 0 + cursorY, 1 + cursorZ };
            int[] p1 = new int[] { 1 + cursorX, 0 + cursorY, 1 + cursorZ };
            int[] p2 = new int[] { 1 + cursorX, 0 + cursorY, 0 + cursorZ };
            int[] p3 = new int[] { 0 + cursorX, 0 + cursorY, 0 + cursorZ };
            int[] p4 = new int[] { 0 + cursorX, 1 + cursorY, 1 + cursorZ };
            int[] p5 = new int[] { 1 + cursorX, 1 + cursorY, 1 + cursorZ };
            int[] p6 = new int[] { 1 + cursorX, 1 + cursorY, 0 + cursorZ };
            int[] p7 = new int[] { 0 + cursorX, 1 + cursorY, 0 + cursorZ };
            double[][] vertlist = new double[12][];
            /* Find the vertices where the surface intersects the cube */
            if (0 != (EDGE_TABLE[cubeindex] & 1)) {
                vertlist[0] = interpolatePoint(p0, p1, vertex_values[0], vertex_values[1]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 2)) {
                vertlist[1] = interpolatePoint(p1, p2, vertex_values[1], vertex_values[2]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 4)) {
                vertlist[2] = interpolatePoint(p2, p3, vertex_values[2], vertex_values[3]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 8)) {
                vertlist[3] = interpolatePoint(p3, p0, vertex_values[3], vertex_values[0]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 16)) {
                vertlist[4] = interpolatePoint(p4, p5, vertex_values[4], vertex_values[5]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 32)) {
                vertlist[5] = interpolatePoint(p5, p6, vertex_values[5], vertex_values[6]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 64)) {
                vertlist[6] = interpolatePoint(p6, p7, vertex_values[6], vertex_values[7]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 128)) {
                vertlist[7] = interpolatePoint(p7, p4, vertex_values[7], vertex_values[4]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 256)) {
                vertlist[8] = interpolatePoint(p0, p4, vertex_values[0], vertex_values[4]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 512)) {
                vertlist[9] = interpolatePoint(p1, p5, vertex_values[1], vertex_values[5]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 1024)) {
                vertlist[10] = interpolatePoint(p2, p6, vertex_values[2], vertex_values[6]);
            }
            if (0 != (EDGE_TABLE[cubeindex] & 2048)) {
                vertlist[11] = interpolatePoint(p3, p7, vertex_values[3], vertex_values[7]);
            }
            /* Create the triangle */
            for (i = 0; TRIANGLE_TABLE[cubeindex][i] != -1; i += 3) {
                TriangularFacet face = new TriangularFacet(new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][0], vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][1], vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][2]), new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][0], vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][1], vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][2]), new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i]][0], vertlist[TRIANGLE_TABLE[cubeindex][i]][1], vertlist[TRIANGLE_TABLE[cubeindex][i]][2]));
                face.getArea();
                output.addFace(face);
            }
        }
    }
    return output;
}
Also used : BoolType(net.imglib2.type.logic.BoolType) Vertex(net.imagej.ops.geom.geom3d.mesh.Vertex) TriangularFacet(net.imagej.ops.geom.geom3d.mesh.TriangularFacet) DefaultMesh(net.imagej.ops.geom.geom3d.mesh.DefaultMesh) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) ExtendedRandomAccessibleInterval(net.imglib2.view.ExtendedRandomAccessibleInterval) FinalInterval(net.imglib2.FinalInterval)

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