Search in sources :

Example 1 with PointSetIterator

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

the class ConvertToMask method run.

// -- Command methods --
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void run() {
    if (!threshSrv.hasThreshold(input)) {
        cancel("This command requires a thresholded image.");
        return;
    }
    ThresholdOverlay thresh = threshSrv.getThreshold(input);
    PointSetIterator iter = thresh.getPointsWithin().iterator();
    if (!iter.hasNext()) {
        cancel("No pixels are within the threshold");
        return;
    }
    Dataset ds = dispSrv.getActiveDataset(input);
    final int numDims = ds.numDimensions();
    final long[] dimensions = new long[numDims];
    final long[] min = new long[numDims];
    /*
		 * First pass - find minima and maxima so we can use a shrunken image in some cases.
		 */
    for (int i = 0; i < numDims; i++) {
        min[i] = (long) Math.floor(thresh.realMin(i));
        dimensions[i] = (long) Math.floor(thresh.realMax(i) - thresh.realMin(i) + 1);
    }
    final ArrayImg<BitType, LongArray> arrayMask = ArrayImgs.bits(dimensions);
    final BitType t = new BitType(arrayMask);
    arrayMask.setLinkedType(t);
    final IntervalView<BitType> mask = Views.translate(arrayMask, min);
    final RandomAccess<BitType> raMask = mask.randomAccess();
    iter.reset();
    while (iter.hasNext()) {
        long[] pos = iter.next();
        raMask.setPosition(pos);
        raMask.get().set(true);
    }
    output = new BinaryMaskOverlay(context, new BinaryMaskRegionOfInterest<BitType, IntervalView<BitType>>(mask));
    output.setAlpha(alpha);
    output.setFillColor(color);
    for (int i = 0; i < numDims; i++) {
        output.setAxis(ds.axis(i), i);
    }
}
Also used : LongArray(net.imglib2.img.basictypeaccess.array.LongArray) BinaryMaskRegionOfInterest(net.imglib2.roi.BinaryMaskRegionOfInterest) ThresholdOverlay(net.imagej.overlay.ThresholdOverlay) PointSetIterator(net.imglib2.ops.pointset.PointSetIterator) BitType(net.imglib2.type.logic.BitType) BinaryMaskOverlay(net.imagej.overlay.BinaryMaskOverlay) Dataset(net.imagej.Dataset)

Example 2 with PointSetIterator

use of net.imglib2.ops.pointset.PointSetIterator 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 3 with PointSetIterator

use of net.imglib2.ops.pointset.PointSetIterator 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)

Example 4 with PointSetIterator

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

the class ImageCalculator method copyDataInto.

// -- private helpers --
private void copyDataInto(final Img<? extends RealType<?>> out, final Img<? extends RealType<?>> in, final long[] span) {
    final RandomAccess<? extends RealType<?>> src = in.randomAccess();
    final RandomAccess<? extends RealType<?>> dst = out.randomAccess();
    final HyperVolumePointSet ps = new HyperVolumePointSet(span);
    final PointSetIterator iter = ps.iterator();
    long[] pos = null;
    while (iter.hasNext()) {
        pos = iter.next();
        src.setPosition(pos);
        dst.setPosition(pos);
        final double value = src.get().getRealDouble();
        dst.get().setReal(value);
    }
}
Also used : PointSetIterator(net.imglib2.ops.pointset.PointSetIterator) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet)

Example 5 with PointSetIterator

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

the class PointSetDemo method run.

@Override
public void run() {
    TextSpecifiedPointSet pointSet = new TextSpecifiedPointSet(specification);
    if (pointSet.getErrorString() != null) {
        cancel(pointSet.getErrorString());
        return;
    }
    long[] minBound = new long[pointSet.numDimensions()];
    long[] maxBound = new long[pointSet.numDimensions()];
    pointSet.min(minBound);
    pointSet.max(maxBound);
    for (int i = 0; i < minBound.length; i++) {
        if ((minBound[i] < 0) || (maxBound[i] < 0)) {
            cancel("For now won't handle negative space with this test plugin");
            return;
        }
        // make a border around the maximum bound
        maxBound[i] += 10;
    }
    output = ds.create(maxBound, "PointSet", null, 8, false, false);
    ImgPlus<? extends RealType<?>> imgplus = output.getImgPlus();
    RandomAccess<? extends RealType<?>> accessor = imgplus.randomAccess();
    PointSetIterator iter = pointSet.iterator();
    while (iter.hasNext()) {
        long[] pos = iter.next();
        accessor.setPosition(pos);
        accessor.get().setReal(255);
    }
}
Also used : TextSpecifiedPointSet(net.imglib2.ops.pointset.TextSpecifiedPointSet) PointSetIterator(net.imglib2.ops.pointset.PointSetIterator)

Aggregations

PointSetIterator (net.imglib2.ops.pointset.PointSetIterator)9 HyperVolumePointSet (net.imglib2.ops.pointset.HyperVolumePointSet)6 Dataset (net.imagej.Dataset)3 AxisType (net.imagej.axis.AxisType)3 PointSet (net.imglib2.ops.pointset.PointSet)3 ThresholdOverlay (net.imagej.overlay.ThresholdOverlay)2 RandomAccess (net.imglib2.RandomAccess)2 BitType (net.imglib2.type.logic.BitType)2 DataRange (net.imagej.autoscale.DataRange)1 CalibratedAxis (net.imagej.axis.CalibratedAxis)1 BinaryMaskOverlay (net.imagej.overlay.BinaryMaskOverlay)1 BigComplex (net.imagej.types.BigComplex)1 LongArray (net.imglib2.img.basictypeaccess.array.LongArray)1 TextSpecifiedPointSet (net.imglib2.ops.pointset.TextSpecifiedPointSet)1 BinaryMaskRegionOfInterest (net.imglib2.roi.BinaryMaskRegionOfInterest)1 DoubleType (net.imglib2.type.numeric.real.DoubleType)1