Search in sources :

Example 11 with HyperVolumePointSet

use of net.imglib2.ops.pointset.HyperVolumePointSet in project imagej-plugins-commands by imagej.

the class MeasurementDemo method example4.

// measuring multiple things at a time
private void example4() {
    Dataset ds = getTestData();
    DoubleType output = new DoubleType();
    RealImageFunction<?, DoubleType> imgFunc = mSrv.imgFunction(ds, output);
    RealArithmeticMeanFunction<DoubleType> meanFunc = new RealArithmeticMeanFunction<DoubleType>(imgFunc);
    RealMinFunction<DoubleType> minFunc = new RealMinFunction<DoubleType>(imgFunc);
    RealMaxFunction<DoubleType> maxFunc = new RealMaxFunction<DoubleType>(imgFunc);
    List<Function<PointSet, DoubleType>> funcList = new ArrayList<Function<PointSet, DoubleType>>();
    List<DoubleType> outputList = new ArrayList<DoubleType>();
    funcList.add(meanFunc);
    funcList.add(minFunc);
    funcList.add(maxFunc);
    outputList.add(new DoubleType());
    outputList.add(new DoubleType());
    outputList.add(new DoubleType());
    PointSet region = new HyperVolumePointSet(Intervals.dimensionsAsLongArray(ds));
    mSrv.measure(funcList, region, outputList);
    System.out.println("mean = " + outputList.get(0).getRealDouble());
    System.out.println("min = " + outputList.get(1).getRealDouble());
    System.out.println("max = " + outputList.get(2).getRealDouble());
}
Also used : RealMaxFunction(net.imglib2.ops.function.real.RealMaxFunction) Dataset(net.imagej.Dataset) ArrayList(java.util.ArrayList) PointSet(net.imglib2.ops.pointset.PointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) RoiPointSet(net.imglib2.ops.pointset.RoiPointSet) BasicStatsFunction(net.imagej.measure.BasicStatsFunction) RealMaxFunction(net.imglib2.ops.function.real.RealMaxFunction) RealAdaptiveMedianFunction(net.imglib2.ops.function.real.RealAdaptiveMedianFunction) RealArithmeticMeanFunction(net.imglib2.ops.function.real.RealArithmeticMeanFunction) RealMinFunction(net.imglib2.ops.function.real.RealMinFunction) RealImageFunction(net.imglib2.ops.function.real.RealImageFunction) Function(net.imglib2.ops.function.Function) RealMedianFunction(net.imglib2.ops.function.real.RealMedianFunction) RealPointCountFunction(net.imglib2.ops.function.real.RealPointCountFunction) RealArithmeticMeanFunction(net.imglib2.ops.function.real.RealArithmeticMeanFunction) DoubleType(net.imglib2.type.numeric.real.DoubleType) RealMinFunction(net.imglib2.ops.function.real.RealMinFunction) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet)

Example 12 with HyperVolumePointSet

use of net.imglib2.ops.pointset.HyperVolumePointSet in project imagej-plugins-commands by imagej.

the class MeasurementDemo method example6.

// measuring a user defined function with the service
private void example6() {
    Dataset ds = getTestData();
    IntType output = new IntType();
    RealImageFunction<?, IntType> imgFunc = mSrv.imgFunction(ds, output);
    CustomFunction func = new CustomFunction(imgFunc);
    PointSet region = new HyperVolumePointSet(Intervals.dimensionsAsLongArray(ds));
    mSrv.measure(func, region, output);
    System.out.println("total 7's = " + output.get());
}
Also used : PointSet(net.imglib2.ops.pointset.PointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) RoiPointSet(net.imglib2.ops.pointset.RoiPointSet) Dataset(net.imagej.Dataset) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) IntType(net.imglib2.type.numeric.integer.IntType)

Example 13 with HyperVolumePointSet

use of net.imglib2.ops.pointset.HyperVolumePointSet in project imagej-plugins-commands by imagej.

the class Reducer method reduceNoise.

// NOTE - because the neighborhood could be a spherical neighborhood that
// relies on a WithinRadiusOfPointCondition we cannot parallelize this
// algorithm. If we did we'd get one point per Thread with only one being
// updated correctly. One can see by trial that using a regular
// ImageAssignment here results in only a portion of the image getting noise
// reduced.
public Dataset reduceNoise(String neighDescrip) {
    notifyUserAtStart(neighDescrip);
    ImgPlus<U> newImg = input.copy();
    long[] dims = new long[newImg.numDimensions()];
    newImg.dimensions(dims);
    PointSet space = new HyperVolumePointSet(dims);
    PointSetInputIterator inputIterator = new PointSetInputIterator(space, neighborhood);
    long[] outputOrigin = new long[input.numDimensions()];
    long[] outputSpan = outputOrigin.clone();
    input.dimensions(outputSpan);
    // NB - regular ImageAssignement won't work here for radial neighborhood due
    // to the duplication of neighborhoods for parallelization and its
    // interference with the WithinRadiusOfPointSetOriginCondition.
    SerialImageAssignment<U, V, PointSet> assigner = new SerialImageAssignment<U, V, PointSet>(newImg, inputFunction, inputIterator, null);
    assigner.assign();
    notifyUserAtEnd(neighDescrip);
    return new DefaultDataset(context, newImg);
}
Also used : HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) PointSet(net.imglib2.ops.pointset.PointSet) SerialImageAssignment(net.imglib2.ops.img.SerialImageAssignment) PointSetInputIterator(net.imglib2.ops.input.PointSetInputIterator) DefaultDataset(net.imagej.DefaultDataset) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet)

Example 14 with HyperVolumePointSet

use of net.imglib2.ops.pointset.HyperVolumePointSet in project imagej-plugins-commands by imagej.

the class HistogramPlot method computeStats.

private void computeStats() {
    // calc stats - 2nd pass thru data
    int chIndex = dataset.dimensionIndex(Axes.CHANNEL);
    int composH = histograms.length - 1;
    RandomAccess<? extends RealType<?>> accessor = dataset.getImgPlus().randomAccess();
    long[] span = Intervals.dimensionsAsLongArray(dataset);
    // iterate channels elsewhere
    if (chIndex >= 0)
        span[chIndex] = 1;
    HyperVolumePointSet pixelSpace = new HyperVolumePointSet(span);
    PointSetIterator pixelSpaceIter = pixelSpace.iterator();
    sampleCount = 0;
    while (pixelSpaceIter.hasNext()) {
        long[] pos = pixelSpaceIter.next();
        accessor.setPosition(pos);
        // count values by channel. also determine composite pixel value (by
        // channel averaging)
        double composVal = 0;
        for (long chan = 0; chan < channels; chan++) {
            if (chIndex >= 0)
                accessor.setPosition(chan, chIndex);
            double val = accessor.get().getRealDouble();
            composVal += val;
            long index = (long) ((val - dataMin) / binWidth);
            // NB in float case the max data point overflows the index range
            if (index >= binCount)
                index = binCount - 1;
            int c = (int) chan;
            histograms[c].increment(index);
            sum1s[c] += val;
            sum2s[c] += val * val;
            if (val < mins[c])
                mins[c] = val;
            if (val > maxes[c])
                maxes[c] = val;
            sampleCount++;
        }
        composVal /= channels;
        long index = (long) ((composVal - dataMin) / binWidth);
        // NB in float case the max data point overflows the index range
        if (index >= binCount)
            index = binCount - 1;
        histograms[composH].increment(index);
        sum1s[composH] += composVal;
        sum2s[composH] += composVal * composVal;
        if (composVal < mins[composH])
            mins[composH] = composVal;
        if (composVal > maxes[composH])
            maxes[composH] = composVal;
    }
    // calc means etc.
    long pixels = sampleCount / channels;
    for (int i = 0; i < histograms.length; i++) {
        means[i] = sum1s[i] / pixels;
        stdDevs[i] = Math.sqrt((sum2s[i] - ((sum1s[i] * sum1s[i]) / pixels)) / (pixels - 1));
    }
}
Also used : PointSetIterator(net.imglib2.ops.pointset.PointSetIterator) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet)

Example 15 with HyperVolumePointSet

use of net.imglib2.ops.pointset.HyperVolumePointSet in project imagej-plugins-commands by imagej.

the class NoiseReductionAdaptiveMedian method getNeighborhoods.

private List<PointSet> getNeighborhoods(final int numDims) {
    final ArrayList<PointSet> pointSets = new ArrayList<PointSet>();
    for (int i = 0; i < windowExpansions; i++) {
        final PointSet rect = new HyperVolumePointSet(new long[numDims], offsets(windowNegWidthSpan + i, windowNegHeightSpan + i, numDims), offsets(windowPosWidthSpan + i, windowPosHeightSpan + i, numDims));
        pointSets.add(rect);
    }
    return pointSets;
}
Also used : PointSet(net.imglib2.ops.pointset.PointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) ArrayList(java.util.ArrayList) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet)

Aggregations

HyperVolumePointSet (net.imglib2.ops.pointset.HyperVolumePointSet)19 PointSet (net.imglib2.ops.pointset.PointSet)12 RoiPointSet (net.imglib2.ops.pointset.RoiPointSet)9 Dataset (net.imagej.Dataset)8 DoubleType (net.imglib2.type.numeric.real.DoubleType)7 PointSetIterator (net.imglib2.ops.pointset.PointSetIterator)6 AxisType (net.imagej.axis.AxisType)5 ArrayList (java.util.ArrayList)3 RealImageFunction (net.imglib2.ops.function.real.RealImageFunction)3 BasicStatsFunction (net.imagej.measure.BasicStatsFunction)2 Overlay (net.imagej.overlay.Overlay)2 RandomAccess (net.imglib2.RandomAccess)2 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)2 RealAdaptiveMedianFunction (net.imglib2.ops.function.real.RealAdaptiveMedianFunction)2 RealArithmeticMeanFunction (net.imglib2.ops.function.real.RealArithmeticMeanFunction)2 RealMaxFunction (net.imglib2.ops.function.real.RealMaxFunction)2 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)2 DefaultDataset (net.imagej.DefaultDataset)1 DataRange (net.imagej.autoscale.DataRange)1 CalibratedAxis (net.imagej.axis.CalibratedAxis)1