Search in sources :

Example 6 with PointSet

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

the class StatisticsDemo method getRegion.

private PointSet getRegion() {
    Overlay overlay = oSrv.getActiveOverlay(display);
    if (overlay != null) {
        return new RoiPointSet(overlay.getRegionOfInterest());
    }
    long[] pt1 = new long[display.numDimensions()];
    long[] pt2 = new long[display.numDimensions()];
    // current plane only
    pt1[0] = 0;
    pt1[1] = 0;
    pt2[0] = display.dimension(0) - 1;
    pt2[1] = display.dimension(1) - 1;
    for (int i = 2; i < display.numDimensions(); i++) {
        pt1[i] = pt2[i] = display.getLongPosition(i);
    }
    return new HyperVolumePointSet(pt1, pt2);
}
Also used : RoiPointSet(net.imglib2.ops.pointset.RoiPointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) Overlay(net.imagej.overlay.Overlay)

Example 7 with PointSet

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

the class Binner method reduceData.

private void reduceData(Dataset ds, List<Integer> reductionFactors) {
    // make the correct Function from the dataset based upon valueMethod.
    Function<PointSet, T> func = function(ds);
    // setup neighborhood to calc from
    PointSet neigh = neighborhood(reductionFactors);
    // make new dimensioned data
    Dataset newDs = newData(ds, reductionFactors);
    // walk each pixel in new dimension, find neighborhood of related point in
    // original space, calc value, and set in newDs.
    long[] currPos = new long[newDs.numDimensions()];
    long[] lastPos = new long[newDs.numDimensions()];
    long[] translation = new long[ds.numDimensions()];
    @SuppressWarnings("unchecked") Cursor<T> cursor = (Cursor<T>) newDs.getImgPlus().localizingCursor();
    T var = cursor.get().createVariable();
    while (cursor.hasNext()) {
        cursor.next();
        cursor.localize(currPos);
        findTranslation(lastPos, currPos, reductionFactors, translation);
        for (int i = 0; i < lastPos.length; i++) {
            lastPos[i] = currPos[i];
        }
        neigh.translate(translation);
        func.compute(neigh, var);
        cursor.get().set(var);
    }
    // TODO
    // update scale of newData's axes?
    // HOW!!!!????
    // This might point out a way to say: setAxis(new ScaleAxis(getAxis())). Can
    // chain these. Thus any axis can be built up from others. It's a thought at
    // least.
    // update data
    ds.setImgPlus(newDs.getImgPlus());
}
Also used : PointSet(net.imglib2.ops.pointset.PointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) Dataset(net.imagej.Dataset) Cursor(net.imglib2.Cursor)

Example 8 with PointSet

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

the class Binarize method planeData.

// returns a PointSet that represents the points in a plane of a dataset
private PointSet planeData(Dataset ds, long[] planePos) {
    long[] pt1 = new long[ds.numDimensions()];
    long[] pt2 = new long[ds.numDimensions()];
    int i = 0;
    for (int d = 0; d < ds.numDimensions(); d++) {
        AxisType type = ds.axis(d).type();
        if (type == Axes.X || type == Axes.Y) {
            pt1[d] = 0;
            pt2[d] = ds.dimension(d) - 1;
        } else {
            pt1[d] = planePos[i];
            pt2[d] = planePos[i];
            i++;
        }
    }
    return new HyperVolumePointSet(pt1, pt2);
}
Also used : AxisType(net.imagej.axis.AxisType) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet)

Example 9 with PointSet

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

the class Binarize method run.

// -- Command methods --
@Override
@SuppressWarnings("unchecked")
public void run() {
    long[] dims = Intervals.dimensionsAsLongArray(inputData);
    String err = checkInputMask(inputMask, dims);
    if (err != null) {
        cancel(err);
        return;
    }
    CalibratedAxis[] axes = new CalibratedAxis[dims.length];
    inputData.axes(axes);
    AxisType[] types = new AxisType[dims.length];
    for (int i = 0; i < dims.length; i++) {
        types[i] = axes[i].type();
    }
    Dataset mask = inputMask != null ? inputMask : datasetSrv.create(new BitType(), dims, "Mask", types, isVirtual(inputData));
    mask.setAxes(axes);
    RandomAccess<BitType> maskAccessor = (RandomAccess<BitType>) mask.getImgPlus().randomAccess();
    RandomAccess<? extends RealType<?>> dataAccessor = inputData.getImgPlus().randomAccess();
    DataRange minMax = calcDataRange(inputData);
    Histogram1d<T> histogram = null;
    boolean testLess = maskPixels.equals(INSIDE);
    DoubleType val = new DoubleType();
    // Better performance? Especially for CellImgs?
    if (thresholdEachPlane && planeCount(inputData) > 1) {
        // threshold each plane separately
        long[] planeSpace = planeSpace(inputData);
        PointSetIterator pIter = new HyperVolumePointSet(planeSpace).iterator();
        while (pIter.hasNext()) {
            long[] planePos = pIter.next();
            histogram = buildHistogram(inputData, planePos, minMax, histogram);
            double cutoffVal = cutoff(histogram, method, testLess, val);
            PointSet planeData = planeData(inputData, planePos);
            PointSetIterator iter = planeData.iterator();
            while (iter.hasNext()) {
                updateMask(iter.next(), testLess, cutoffVal, dataAccessor, maskAccessor);
            }
        }
    } else {
        // threshold entire dataset once
        histogram = buildHistogram(inputData, null, minMax, null);
        double cutoffVal = cutoff(histogram, method, testLess, val);
        PointSet fullData = fullData(dims);
        PointSetIterator iter = fullData.iterator();
        while (iter.hasNext()) {
            updateMask(iter.next(), testLess, cutoffVal, dataAccessor, maskAccessor);
        }
    }
    assignColorTables(mask);
    if (changeInput) {
        // TODO - should inputData be ItemIO.BOTH????
        inputData.setImgPlus(mask.getImgPlus());
    } else
        outputMask = mask;
}
Also used : Dataset(net.imagej.Dataset) RandomAccess(net.imglib2.RandomAccess) PointSet(net.imglib2.ops.pointset.PointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) PointSetIterator(net.imglib2.ops.pointset.PointSetIterator) BitType(net.imglib2.type.logic.BitType) DoubleType(net.imglib2.type.numeric.real.DoubleType) AxisType(net.imagej.axis.AxisType) DataRange(net.imagej.autoscale.DataRange) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) CalibratedAxis(net.imagej.axis.CalibratedAxis)

Example 10 with PointSet

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

the class NanBackground method assignPixels.

private void assignPixels() {
    ThresholdOverlay thresh = threshSrv.getThreshold(display);
    PointSet ps = thresh.getPointsOutside();
    PointSetIterator iter = ps.iterator();
    RandomAccess<? extends RealType<?>> accessor = input.getImgPlus().randomAccess();
    while (iter.hasNext()) {
        long[] pos = iter.next();
        accessor.setPosition(pos);
        accessor.get().setReal(Double.NaN);
    }
}
Also used : PointSet(net.imglib2.ops.pointset.PointSet) ThresholdOverlay(net.imagej.overlay.ThresholdOverlay) PointSetIterator(net.imglib2.ops.pointset.PointSetIterator)

Aggregations

HyperVolumePointSet (net.imglib2.ops.pointset.HyperVolumePointSet)18 PointSet (net.imglib2.ops.pointset.PointSet)17 DoubleType (net.imglib2.type.numeric.real.DoubleType)10 Dataset (net.imagej.Dataset)9 RoiPointSet (net.imglib2.ops.pointset.RoiPointSet)9 RealImageFunction (net.imglib2.ops.function.real.RealImageFunction)5 AxisType (net.imagej.axis.AxisType)4 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)4 PointSetIterator (net.imglib2.ops.pointset.PointSetIterator)4 ArrayList (java.util.ArrayList)3 ImgPlus (net.imagej.ImgPlus)2 BasicStatsFunction (net.imagej.measure.BasicStatsFunction)2 Overlay (net.imagej.overlay.Overlay)2 RandomAccess (net.imglib2.RandomAccess)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 OutOfBoundsMirrorFactory (net.imglib2.outofbounds.OutOfBoundsMirrorFactory)2 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)2 DefaultDataset (net.imagej.DefaultDataset)1