Search in sources :

Example 1 with IntegralCursor

use of net.imagej.ops.image.integral.IntegralCursor 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 2 with IntegralCursor

use of net.imagej.ops.image.integral.IntegralCursor 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)

Example 3 with IntegralCursor

use of net.imagej.ops.image.integral.IntegralCursor in project imagej-ops by imagej.

the class IntegralSum method compute.

@Override
public void compute(final RectangleNeighborhood<I> input, final DoubleType output) {
    // computation according to
    // https://en.wikipedia.org/wiki/Summed_area_table
    final IntegralCursor<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().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);
    }
    output.set(sum);
}
Also used : 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)3 RealDoubleConverter (net.imglib2.converter.RealDoubleConverter)3 DoubleType (net.imglib2.type.numeric.real.DoubleType)3 Composite (net.imglib2.view.composite.Composite)2