Search in sources :

Example 6 with DoubleType

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());
    }
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType)

Example 7 with DoubleType

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;
}
Also used : UnaryComputerOp(net.imagej.ops.special.computer.UnaryComputerOp) Ops(net.imagej.ops.Ops) BitType(net.imglib2.type.logic.BitType) DoubleType(net.imglib2.type.numeric.real.DoubleType) LocalThresholdMethod(net.imagej.ops.threshold.LocalThresholdMethod)

Example 8 with DoubleType

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);
}
Also used : Composite(net.imglib2.view.composite.Composite) DoubleType(net.imglib2.type.numeric.real.DoubleType) IntegralCursor(net.imagej.ops.image.integral.IntegralCursor) RealDoubleConverter(net.imglib2.converter.RealDoubleConverter)

Example 9 with DoubleType

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;
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) ValuePair(net.imglib2.util.ValuePair) ArrayList(java.util.ArrayList) LongStream(java.util.stream.LongStream)

Example 10 with DoubleType

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;
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) RealPoint(net.imglib2.RealPoint) Point(net.imglib2.Point)

Aggregations

DoubleType (net.imglib2.type.numeric.real.DoubleType)185 Test (org.junit.Test)123 AbstractOpTest (net.imagej.ops.AbstractOpTest)111 LongType (net.imglib2.type.numeric.integer.LongType)37 MersenneTwisterFast (org.scijava.util.MersenneTwisterFast)19 ArrayList (java.util.ArrayList)14 Dataset (net.imagej.Dataset)14 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)13 Img (net.imglib2.img.Img)10 PointSet (net.imglib2.ops.pointset.PointSet)10 Ops (net.imagej.ops.Ops)9 HyperVolumePointSet (net.imglib2.ops.pointset.HyperVolumePointSet)9 Overlay (net.imagej.overlay.Overlay)8 FinalDimensions (net.imglib2.FinalDimensions)8 FinalInterval (net.imglib2.FinalInterval)8 BitType (net.imglib2.type.logic.BitType)8 DatasetView (net.imagej.display.DatasetView)7 Dimensions (net.imglib2.Dimensions)7 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)7 RealLocalizable (net.imglib2.RealLocalizable)6