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);
}
}
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);
}
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");
}
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;
}
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;
}
Aggregations