Search in sources :

Example 6 with Interval

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

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

Aggregations

FinalInterval (net.imglib2.FinalInterval)5 BitType (net.imglib2.type.logic.BitType)4 File (java.io.File)2 Dataset (net.imagej.Dataset)2 ImgPlus (net.imagej.ImgPlus)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1 CalibratedAxis (net.imagej.axis.CalibratedAxis)1 DefaultLinearAxis (net.imagej.axis.DefaultLinearAxis)1 Interval (net.imglib2.Interval)1 IterableInterval (net.imglib2.IterableInterval)1 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)1 Img (net.imglib2.img.Img)1 LabelRegion (net.imglib2.roi.labeling.LabelRegion)1 LabelRegionCursor (net.imglib2.roi.labeling.LabelRegionCursor)1 LabelRegions (net.imglib2.roi.labeling.LabelRegions)1 LabelingType (net.imglib2.roi.labeling.LabelingType)1 ByteType (net.imglib2.type.numeric.integer.ByteType)1