Search in sources :

Example 1 with Composite

use of net.imglib2.view.composite.Composite in project imagej-ops by imagej.

the class LocalThresholdIntegral method removeLeadingZeros.

/**
 * Removes leading 0s from integral image after composite creation.
 *
 * @param input Input RAI (can be a RAI of Composite)
 * @return An extended and cropped version of input
 */
private <T> RandomAccessibleInterval<T> removeLeadingZeros(final RandomAccessibleInterval<T> input) {
    // Remove 0s from integralImg by shifting its interval by +1
    final long[] min = Intervals.minAsLongArray(input);
    final long[] max = Intervals.maxAsLongArray(input);
    for (int d = 0; d < input.numDimensions(); ++d) {
        int correctedSpan = getShape().getSpan() - 1;
        min[d] += (1 + correctedSpan);
        max[d] -= correctedSpan;
    }
    // Define the Interval on the infinite random accessibles
    final FinalInterval interval = new FinalInterval(min, max);
    final RandomAccessibleInterval<T> extendedImg = Views.offsetInterval(Views.extendBorder(input), interval);
    return extendedImg;
}
Also used : FinalInterval(net.imglib2.FinalInterval)

Example 2 with Composite

use of net.imglib2.view.composite.Composite 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 3 with Composite

use of net.imglib2.view.composite.Composite in project imagej-ops by imagej.

the class IntegralMean 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>> cursor = new IntegralCursor<>(input);
    final int dimensions = input.numDimensions();
    // Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
    final DoubleType sum = new DoubleType();
    sum.setZero();
    // Convert from input to return type
    final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
    final DoubleType valueAsDoubleType = new DoubleType();
    while (cursor.hasNext()) {
        final I value = cursor.next().get(0).copy();
        conv.convert(value, valueAsDoubleType);
        // Obtain the cursor position encoded as corner vector
        final int cornerInteger = cursor.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(cornerInteger)));
        valueAsDoubleType.mul(factor);
        sum.add(valueAsDoubleType);
    }
    final int area = (int) Intervals.numElements(Intervals.expand(input, -1l));
    // Compute mean by dividing the sum divided by the number of elements
    // NB: Reuse DoubleType
    valueAsDoubleType.set(area);
    sum.div(valueAsDoubleType);
    output.set(sum);
}
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)

Aggregations

IntegralCursor (net.imagej.ops.image.integral.IntegralCursor)2 RealDoubleConverter (net.imglib2.converter.RealDoubleConverter)2 DoubleType (net.imglib2.type.numeric.real.DoubleType)2 Composite (net.imglib2.view.composite.Composite)2 FinalInterval (net.imglib2.FinalInterval)1