use of net.imglib2.type.numeric.real.DoubleType in project bigwarp by saalfeldlab.
the class GridRealRandomAccess method main.
public static void main(String[] args) {
GridRealRandomAccess<DoubleType> ra = new GridRealRandomAccess<DoubleType>(new double[] { 100.0, 100.0 }, new DoubleType(), null);
ra.setMethod(GRID_TYPE.LINE);
for (double x = 2.1; x < 5.0; x += 1.0) for (double y = 0.0; y < 5.0; y += 0.5) {
ra.setPosition(new double[] { x, y });
System.out.println("(" + x + "," + y + ") : " + ra.get());
}
}
use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.
the class LocalPhansalkarThreshold method unaryComputer.
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass, final BitType outClass) {
final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {
private UnaryComputerOp<Iterable<T>, DoubleType> mean;
private UnaryComputerOp<Iterable<T>, DoubleType> stdDeviation;
@Override
public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {
if (mean == null) {
mean = Computers.unary(ops(), Ops.Stats.Mean.class, new DoubleType(), neighborhood);
}
if (stdDeviation == null) {
stdDeviation = Computers.unary(ops(), Ops.Stats.StdDev.class, new DoubleType(), neighborhood);
}
final DoubleType meanValue = new DoubleType();
mean.compute(neighborhood, meanValue);
final DoubleType stdDevValue = new DoubleType();
stdDeviation.compute(neighborhood, stdDevValue);
double threshold = meanValue.get() * (1.0d + p * Math.exp(-q * meanValue.get()) + k * ((stdDevValue.get() / r) - 1.0));
output.set(center.getRealDouble() >= threshold);
}
};
op.setEnvironment(ops());
return op;
}
use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.
the class IntegralVariance method compute.
@Override
public void compute(final RectangleNeighborhood<Composite<I>> input, final DoubleType output) {
// computation according to
// https://en.wikipedia.org/wiki/Summed_area_table
final IntegralCursor<Composite<I>> cursorS1 = new IntegralCursor<>(input);
final int dimensions = input.numDimensions();
// Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
final DoubleType sum1 = new DoubleType();
sum1.setZero();
// Convert from input to return type
final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
// Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
final DoubleType sum2 = new DoubleType();
sum2.setZero();
final DoubleType valueAsDoubleType = new DoubleType();
while (cursorS1.hasNext()) {
final Composite<I> compositeValue = cursorS1.next();
final I value1 = compositeValue.get(0).copy();
conv.convert(value1, valueAsDoubleType);
// Obtain the cursor position encoded as corner vector
final int cornerInteger1 = cursorS1.getCornerRepresentation();
// Determine if the value has to be added (factor==1) or subtracted
// (factor==-1)
final DoubleType factor = new DoubleType(Math.pow(-1.0d, dimensions - IntegralMean.norm(cornerInteger1)));
valueAsDoubleType.mul(factor);
sum1.add(valueAsDoubleType);
final I value2 = compositeValue.get(1).copy();
conv.convert(value2, valueAsDoubleType);
// Determine if the value has to be added (factor==1) or subtracted
// (factor==-1)
valueAsDoubleType.mul(factor);
sum2.add(valueAsDoubleType);
}
final int area = (int) Intervals.numElements(Intervals.expand(input, -1l));
// NB: Reuse available DoubleType
valueAsDoubleType.set(area);
sum1.mul(sum1);
// NB
sum1.div(valueAsDoubleType);
sum2.sub(sum1);
// NB
valueAsDoubleType.sub(new DoubleType(1));
// NB
sum2.div(valueAsDoubleType);
output.set(sum2);
}
use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.
the class BoxCount method calculate.
/**
* Counts the number of boxes that have foreground in the interval repeatedly with
* different size boxes
*
* @param input An n-dimensional binary interval.
* @return A list of (log(foreground count), -log(box size))
* {@link ValuePair} objects for curve fitting
*/
@Override
public List<ValuePair<DoubleType, DoubleType>> calculate(final RandomAccessibleInterval<B> input) {
if (scaling < 1.0 || (scaling == 1.0 && maxSize > minSize)) {
throw new IllegalArgumentException("Scaling must be > 1.0 or algorithm won't stop.");
}
final List<ValuePair<DoubleType, DoubleType>> points = new ArrayList<>();
final int dimensions = input.numDimensions();
final long[] sizes = new long[dimensions];
input.dimensions(sizes);
for (long boxSize = maxSize; boxSize >= minSize; boxSize /= scaling) {
final long numTranslations = limitTranslations(boxSize, 1 + gridMoves);
final long translationAmount = boxSize / numTranslations;
final Stream<long[]> translations = translationStream(numTranslations, translationAmount, dimensions - 1, new long[dimensions]);
final LongStream foregroundCounts = countTranslatedGrids(input, translations, sizes, boxSize);
final long foreground = foregroundCounts.min().orElse(0);
final double logSize = -Math.log(boxSize);
final double logCount = Math.log(foreground);
final ValuePair<DoubleType, DoubleType> point = new ValuePair<>(new DoubleType(logSize), new DoubleType(logCount));
points.add(point);
}
return points;
}
use of net.imglib2.type.numeric.real.DoubleType in project imagej-ops by imagej.
the class RidgeDetectionUtils method getMaxCoords.
protected static long[] getMaxCoords(RandomAccessibleInterval<DoubleType> input, boolean useAbsoluteValue) {
long[] dims = new long[input.numDimensions()];
double max = Double.MIN_VALUE;
Cursor<DoubleType> cursor = Views.iterable(input).localizingCursor();
while (cursor.hasNext()) {
cursor.fwd();
double current = useAbsoluteValue ? Math.abs(cursor.get().get()) : cursor.get().get();
if (current > max) {
max = current;
for (int d = 0; d < input.numDimensions(); d++) {
dims[d] = cursor.getLongPosition(d);
}
}
}
return dims;
}
Aggregations