use of net.imglib2.ops.pointset.HyperVolumePointSet in project imagej-plugins-commands by imagej.
the class MeasurementDemo method example4.
// measuring multiple things at a time
private void example4() {
Dataset ds = getTestData();
DoubleType output = new DoubleType();
RealImageFunction<?, DoubleType> imgFunc = mSrv.imgFunction(ds, output);
RealArithmeticMeanFunction<DoubleType> meanFunc = new RealArithmeticMeanFunction<DoubleType>(imgFunc);
RealMinFunction<DoubleType> minFunc = new RealMinFunction<DoubleType>(imgFunc);
RealMaxFunction<DoubleType> maxFunc = new RealMaxFunction<DoubleType>(imgFunc);
List<Function<PointSet, DoubleType>> funcList = new ArrayList<Function<PointSet, DoubleType>>();
List<DoubleType> outputList = new ArrayList<DoubleType>();
funcList.add(meanFunc);
funcList.add(minFunc);
funcList.add(maxFunc);
outputList.add(new DoubleType());
outputList.add(new DoubleType());
outputList.add(new DoubleType());
PointSet region = new HyperVolumePointSet(Intervals.dimensionsAsLongArray(ds));
mSrv.measure(funcList, region, outputList);
System.out.println("mean = " + outputList.get(0).getRealDouble());
System.out.println("min = " + outputList.get(1).getRealDouble());
System.out.println("max = " + outputList.get(2).getRealDouble());
}
use of net.imglib2.ops.pointset.HyperVolumePointSet in project imagej-plugins-commands by imagej.
the class MeasurementDemo method example6.
// measuring a user defined function with the service
private void example6() {
Dataset ds = getTestData();
IntType output = new IntType();
RealImageFunction<?, IntType> imgFunc = mSrv.imgFunction(ds, output);
CustomFunction func = new CustomFunction(imgFunc);
PointSet region = new HyperVolumePointSet(Intervals.dimensionsAsLongArray(ds));
mSrv.measure(func, region, output);
System.out.println("total 7's = " + output.get());
}
use of net.imglib2.ops.pointset.HyperVolumePointSet 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.HyperVolumePointSet in project imagej-plugins-commands by imagej.
the class HistogramPlot method computeStats.
private void computeStats() {
// calc stats - 2nd pass thru data
int chIndex = dataset.dimensionIndex(Axes.CHANNEL);
int composH = histograms.length - 1;
RandomAccess<? extends RealType<?>> accessor = dataset.getImgPlus().randomAccess();
long[] span = Intervals.dimensionsAsLongArray(dataset);
// iterate channels elsewhere
if (chIndex >= 0)
span[chIndex] = 1;
HyperVolumePointSet pixelSpace = new HyperVolumePointSet(span);
PointSetIterator pixelSpaceIter = pixelSpace.iterator();
sampleCount = 0;
while (pixelSpaceIter.hasNext()) {
long[] pos = pixelSpaceIter.next();
accessor.setPosition(pos);
// count values by channel. also determine composite pixel value (by
// channel averaging)
double composVal = 0;
for (long chan = 0; chan < channels; chan++) {
if (chIndex >= 0)
accessor.setPosition(chan, chIndex);
double val = accessor.get().getRealDouble();
composVal += val;
long index = (long) ((val - dataMin) / binWidth);
// NB in float case the max data point overflows the index range
if (index >= binCount)
index = binCount - 1;
int c = (int) chan;
histograms[c].increment(index);
sum1s[c] += val;
sum2s[c] += val * val;
if (val < mins[c])
mins[c] = val;
if (val > maxes[c])
maxes[c] = val;
sampleCount++;
}
composVal /= channels;
long index = (long) ((composVal - dataMin) / binWidth);
// NB in float case the max data point overflows the index range
if (index >= binCount)
index = binCount - 1;
histograms[composH].increment(index);
sum1s[composH] += composVal;
sum2s[composH] += composVal * composVal;
if (composVal < mins[composH])
mins[composH] = composVal;
if (composVal > maxes[composH])
maxes[composH] = composVal;
}
// calc means etc.
long pixels = sampleCount / channels;
for (int i = 0; i < histograms.length; i++) {
means[i] = sum1s[i] / pixels;
stdDevs[i] = Math.sqrt((sum2s[i] - ((sum1s[i] * sum1s[i]) / pixels)) / (pixels - 1));
}
}
use of net.imglib2.ops.pointset.HyperVolumePointSet 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;
}
Aggregations