Search in sources :

Example 1 with BooleanType

use of net.imglib2.type.BooleanType in project imagej-ops by imagej.

the class BoxCount method countTranslatedGrids.

/**
 * Count foreground sections in all grids created from the translations
 *
 * @param input N-dimensional binary interval
 * @param translations Stream of translation coordinates in n-dimensions
 * @param sizes Sizes of the interval's dimensions in pixels
 * @param sectionSize Size of a section in the grids
 * @return Foreground sections counted in each grid
 */
private static <B extends BooleanType<B>> LongStream countTranslatedGrids(final RandomAccessibleInterval<B> input, final Stream<long[]> translations, final long[] sizes, final long sectionSize) {
    final int lastDimension = sizes.length - 1;
    final LongType foreground = new LongType();
    final long[] sectionPosition = new long[sizes.length];
    return translations.mapToLong(gridOffset -> {
        foreground.setZero();
        Arrays.fill(sectionPosition, 0);
        countGrid(input, lastDimension, sizes, gridOffset, sectionPosition, sectionSize, foreground);
        return foreground.get();
    });
}
Also used : LongType(net.imglib2.type.numeric.integer.LongType)

Example 2 with BooleanType

use of net.imglib2.type.BooleanType in project imagej-ops by imagej.

the class BoxCount method sectionView.

/**
 * Creates a {@link net.imglib2.View} of the given grid section in the
 * interval
 * <p>
 * Fits the view inside the bounds of the interval.
 * </p>
 *
 * @param interval An n-dimensional interval with binary elements
 * @param sizes Sizes of the interval's dimensions
 * @param coordinates Starting coordinates of the section
 * @param sectionSize Size of the section (n * n * ... n)
 * @return A view of the interval spanning n pixels in each dimension from the
 *         coordinates. Null if view couldn't be set inside the interval
 */
private static <B extends BooleanType<B>> IntervalView<B> sectionView(final RandomAccessibleInterval<B> interval, final long[] sizes, final long[] coordinates, final long sectionSize) {
    final int n = sizes.length;
    final long[] startPosition = IntStream.range(0, n).mapToLong(i -> Math.max(0, coordinates[i])).toArray();
    final long[] endPosition = IntStream.range(0, n).mapToLong(i -> Math.min((sizes[i] - 1), (coordinates[i] + sectionSize - 1))).toArray();
    final boolean badBox = IntStream.range(0, n).anyMatch(d -> (startPosition[d] >= sizes[d]) || (endPosition[d] < 0) || (endPosition[d] < startPosition[d]));
    if (badBox) {
        return null;
    }
    final BoundingBox box = new BoundingBox(n);
    box.update(startPosition);
    box.update(endPosition);
    return Views.offsetInterval(interval, box);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) LongStream(java.util.stream.LongStream) Parameter(org.scijava.plugin.Parameter) BoundingBox(net.imglib2.roi.labeling.BoundingBox) AbstractUnaryFunctionOp(net.imagej.ops.special.function.AbstractUnaryFunctionOp) ArrayList(java.util.ArrayList) ValuePair(net.imglib2.util.ValuePair) IntervalView(net.imglib2.view.IntervalView) Plugin(org.scijava.plugin.Plugin) List(java.util.List) Stream(java.util.stream.Stream) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) BooleanType(net.imglib2.type.BooleanType) DoubleType(net.imglib2.type.numeric.real.DoubleType) Ops(net.imagej.ops.Ops) StreamSupport(java.util.stream.StreamSupport) LongType(net.imglib2.type.numeric.integer.LongType) Spliterator(java.util.Spliterator) Views(net.imglib2.view.Views) BoundingBox(net.imglib2.roi.labeling.BoundingBox)

Aggregations

LongType (net.imglib2.type.numeric.integer.LongType)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Spliterator (java.util.Spliterator)1 IntStream (java.util.stream.IntStream)1 LongStream (java.util.stream.LongStream)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Ops (net.imagej.ops.Ops)1 AbstractUnaryFunctionOp (net.imagej.ops.special.function.AbstractUnaryFunctionOp)1 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)1 BoundingBox (net.imglib2.roi.labeling.BoundingBox)1 BooleanType (net.imglib2.type.BooleanType)1 DoubleType (net.imglib2.type.numeric.real.DoubleType)1 ValuePair (net.imglib2.util.ValuePair)1 IntervalView (net.imglib2.view.IntervalView)1 Views (net.imglib2.view.Views)1 Parameter (org.scijava.plugin.Parameter)1 Plugin (org.scijava.plugin.Plugin)1