Search in sources :

Example 16 with PointSet

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

Example 17 with PointSet

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

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

the class MathCommand method initialize.

// -- private helpers --
private void initialize() {
    dataset = displayService.getActiveDataset(display);
    overlay = overlayService.getActiveOverlay(display);
    DatasetView view = displayService.getActiveDatasetView(display);
    planePos = view.getPlanePosition();
    InplaceUnaryTransform<?, ?> xform = getPreviewTransform(dataset, overlay);
    PointSet region = determineRegion(dataset, xform.getRegionOrigin(), xform.getRegionSpan());
    iter = region.iterator();
    ArrayImgFactory<DoubleType> factory = new ArrayImgFactory<DoubleType>();
    dataBackup = factory.create(new long[] { region.size() }, new DoubleType());
    backupAccess = dataBackup.randomAccess();
    dataAccess = dataset.getImgPlus().randomAccess();
    // check dimensions of Dataset
    final long w = xform.getRegionSpan()[0];
    final long h = xform.getRegionSpan()[1];
    if (w * h > Integer.MAX_VALUE)
        throw new IllegalArgumentException("preview region too large to copy into memory");
}
Also used : PointSet(net.imglib2.ops.pointset.PointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) DatasetView(net.imagej.display.DatasetView) DoubleType(net.imglib2.type.numeric.real.DoubleType) ArrayImgFactory(net.imglib2.img.array.ArrayImgFactory)

Example 19 with PointSet

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

Example 20 with PointSet

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

the class TypeChanger method channelAveragingCase.

// -- helpers --
@SuppressWarnings("unchecked")
private Dataset channelAveragingCase(DataType<U> inType, DataType<V> outType, int chAxis, int count) {
    BigComplex[] temps = new BigComplex[count];
    for (int i = 0; i < count; i++) {
        temps[i] = new BigComplex();
    }
    BigComplex combined = new BigComplex();
    BigComplex divisor = new BigComplex(count, 0);
    long[] dims = calcDims(Intervals.dimensionsAsLongArray(data), chAxis);
    AxisType[] axes = calcAxes(SpaceUtils.getAxisTypes(data), chAxis);
    Dataset newData = datasetService.create(outType.createVariable(), dims, "Converted Image", axes);
    long[] span = Intervals.dimensionsAsLongArray(data).clone();
    span[chAxis] = 1;
    PointSet combinedSpace = new HyperVolumePointSet(span);
    PointSetIterator iter = combinedSpace.iterator();
    RandomAccess<U> inAccessor = (RandomAccess<U>) data.getImgPlus().randomAccess();
    RandomAccess<V> outAccessor = (RandomAccess<V>) newData.getImgPlus().randomAccess();
    while (iter.hasNext()) {
        long[] pos = iter.next();
        inAccessor.setPosition(pos);
        for (int i = 0; i < count; i++) {
            inAccessor.setPosition(i, chAxis);
            inType.cast(inAccessor.get(), temps[i]);
        }
        combined.setZero();
        for (int i = 0; i < count; i++) {
            combined.add(temps[i]);
        }
        int d = 0;
        for (int i = 0; i < count; i++) {
            if (i == chAxis)
                continue;
            outAccessor.setPosition(pos[i], d++);
        }
        combined.div(divisor);
        outType.cast(combined, outAccessor.get());
    }
    copyMetaDataChannelsCase(data.getImgPlus(), newData.getImgPlus());
    return newData;
}
Also used : Dataset(net.imagej.Dataset) BigComplex(net.imagej.types.BigComplex) RandomAccess(net.imglib2.RandomAccess) PointSet(net.imglib2.ops.pointset.PointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) PointSetIterator(net.imglib2.ops.pointset.PointSetIterator) AxisType(net.imagej.axis.AxisType) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet)

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