Search in sources :

Example 1 with BoundingBox

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

Example 2 with BoundingBox

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);
}
Also used : BitType(net.imglib2.type.logic.BitType) RandomAccess(net.imglib2.RandomAccess) Arrays(java.util.Arrays) OutOfBounds(net.imglib2.outofbounds.OutOfBounds) BoundingBox(net.imglib2.roi.labeling.BoundingBox) Util(net.imglib2.util.Util) IntervalView(net.imglib2.view.IntervalView) Plugin(org.scijava.plugin.Plugin) AbstractBinaryHybridCF(net.imagej.ops.special.hybrid.AbstractBinaryHybridCF) Cursor(net.imglib2.Cursor) FinalDimensions(net.imglib2.FinalDimensions) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) BooleanType(net.imglib2.type.BooleanType) Ops(net.imagej.ops.Ops) Views(net.imglib2.view.Views) ExtendedRandomAccessibleInterval(net.imglib2.view.ExtendedRandomAccessibleInterval) BoundingBox(net.imglib2.roi.labeling.BoundingBox)

Example 3 with BoundingBox

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);
    }
}
Also used : RealPoint(net.imglib2.RealPoint) Polygon2D(net.imglib2.roi.geom.real.Polygon2D) RealPoint(net.imglib2.RealPoint) DefaultBoundingBox(net.imagej.ops.geom.geom2d.DefaultBoundingBox) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Aggregations

Arrays (java.util.Arrays)2 Ops (net.imagej.ops.Ops)2 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)2 BoundingBox (net.imglib2.roi.labeling.BoundingBox)2 BooleanType (net.imglib2.type.BooleanType)2 IntervalView (net.imglib2.view.IntervalView)2 Views (net.imglib2.view.Views)2 Plugin (org.scijava.plugin.Plugin)2 ArrayList (java.util.ArrayList)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 AbstractFeatureTest (net.imagej.ops.features.AbstractFeatureTest)1 DefaultBoundingBox (net.imagej.ops.geom.geom2d.DefaultBoundingBox)1 AbstractUnaryFunctionOp (net.imagej.ops.special.function.AbstractUnaryFunctionOp)1 AbstractBinaryHybridCF (net.imagej.ops.special.hybrid.AbstractBinaryHybridCF)1 Cursor (net.imglib2.Cursor)1