use of net.imglib2.ops.pointset.HyperVolumePointSet 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);
}
use of net.imglib2.ops.pointset.HyperVolumePointSet 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);
}
use of net.imglib2.ops.pointset.HyperVolumePointSet 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;
}
use of net.imglib2.ops.pointset.HyperVolumePointSet 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);
}
}
use of net.imglib2.ops.pointset.HyperVolumePointSet in project imagej-plugins-commands by imagej.
the class MeasurementDemo method example1.
// -- Other examples --
// standard ways of measuring various values.
// a basic measurement
private void example1() {
Dataset ds = getTestData();
DoubleType output = new DoubleType();
RealImageFunction<?, DoubleType> imgFunc = mSrv.imgFunction(ds, output);
RealArithmeticMeanFunction<DoubleType> meanFunc = new RealArithmeticMeanFunction<DoubleType>(imgFunc);
PointSet region = new HyperVolumePointSet(Intervals.dimensionsAsLongArray(ds));
mSrv.measure(meanFunc, region, output);
System.out.println("arithmetic mean is " + output.getRealDouble());
}
Aggregations