Java Code Examples for net.imglib2.type.numeric.real.DoubleType#setZero()

The following examples show how to use net.imglib2.type.numeric.real.DoubleType#setZero() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntegralSum.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example 2
Source File: DefaultTubeness.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Iterable<DoubleType> input,
	final DoubleType output)
{
	// Use just the largest one.
	final Iterator<DoubleType> it = input.iterator();
	it.next();
	final double val = it.next().get();
	if (val >= 0.) output.setZero();
	else output.set(sigma * sigma * Math.abs(val));

}
 
Example 3
Source File: DefaultTubeness.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Iterable<DoubleType> input,
	final DoubleType output)
{
	// Use the two largest ones.
	final Iterator<DoubleType> it = input.iterator();
	it.next();
	final double val1 = it.next().get();
	final double val2 = it.next().get();
	if (val1 >= 0. || val2 >= 0.) output.setZero();
	else output.set(sigma * sigma * Math.sqrt(val1 * val2));

}
 
Example 4
Source File: IntegralVariance.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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));

	valueAsDoubleType.set(area); // NB: Reuse available DoubleType
	sum1.mul(sum1);
	sum1.div(valueAsDoubleType); // NB

	sum2.sub(sum1);
	valueAsDoubleType.sub(new DoubleType(1)); // NB
	sum2.div(valueAsDoubleType); // NB

	output.set(sum2);
}
 
Example 5
Source File: IntegralMean.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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
	valueAsDoubleType.set(area); // NB: Reuse DoubleType
	sum.div(valueAsDoubleType);

	output.set(sum);
}