use of net.imglib2.roi.labeling.BoundingBox 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);
}
use of net.imglib2.roi.labeling.BoundingBox in project imagej-ops by imagej.
the class Outline method neighbourhoodInterval.
/**
* Creates a view that spans from (x-1, y-1, ... i-1) to (x+1, y+1, ... i+1)
* around the given coordinates
*
* @param interval the space of the coordinates
* @param coordinates coordinates (x, y, ... i)
* @return a view of a neighbourhood in the space
*/
private IntervalView<B> neighbourhoodInterval(final ExtendedRandomAccessibleInterval<B, RandomAccessibleInterval<B>> interval, final long[] coordinates) {
final int dimensions = interval.numDimensions();
final BoundingBox box = new BoundingBox(dimensions);
final long[] minBounds = Arrays.stream(coordinates).map(c -> c - 1).toArray();
final long[] maxBounds = Arrays.stream(coordinates).map(c -> c + 1).toArray();
box.update(minBounds);
box.update(maxBounds);
return Views.offsetInterval(interval, box);
}
use of net.imglib2.roi.labeling.BoundingBox in project imagej-ops by imagej.
the class PolygonFeatureTests method boundingBox.
@Test
public void boundingBox() {
// ground truth verified with matlab
final List<? extends RealLocalizable> received = GeomUtils.vertices(((Polygon2D) ops.run(DefaultBoundingBox.class, contour)));
final RealPoint[] expected = new RealPoint[] { new RealPoint(1, 6), new RealPoint(1, 109), new RealPoint(78, 109), new RealPoint(78, 6) };
assertEquals("Number of polygon points differs.", expected.length, received.size());
for (int i = 0; i < expected.length; i++) {
assertEquals("Polygon point " + i + " differs in x-coordinate.", expected[i].getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON);
assertEquals("Polygon point " + i + " differs in y-coordinate.", expected[i].getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON);
}
}
Aggregations