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();
});
}
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);
}
Aggregations