Search in sources :

Example 11 with RealLocalizable

use of net.imglib2.RealLocalizable in project imagej-ops by imagej.

the class DefaultCenterOfGravity method calculate.

@Override
public RealLocalizable calculate(final IterableInterval<T> input) {
    final int numDimensions = input.numDimensions();
    final double[] output = new double[numDimensions];
    final double[] intensityValues = new double[numDimensions];
    final Cursor<T> c = input.localizingCursor();
    while (c.hasNext()) {
        c.fwd();
        for (int i = 0; i < output.length; i++) {
            output[i] += c.getDoublePosition(i) * c.get().getRealDouble();
            intensityValues[i] += c.get().getRealDouble();
        }
    }
    for (int i = 0; i < output.length; i++) {
        output[i] = output[i] / intensityValues[i];
    }
    return new RealPoint(output);
}
Also used : RealPoint(net.imglib2.RealPoint) RealPoint(net.imglib2.RealPoint)

Example 12 with RealLocalizable

use of net.imglib2.RealLocalizable in project imagej-ops by imagej.

the class PolygonFeatureTests method labelRegionToPolygonConverter.

@Test
public void labelRegionToPolygonConverter() {
    // ground truth computed with matlab
    final LabelRegionToPolygonConverter c = new LabelRegionToPolygonConverter();
    c.setContext(ops.context());
    final Polygon2D test = c.convert(ROI, Polygon2D.class);
    final List<? extends RealLocalizable> expected = GeomUtils.vertices(contour);
    final List<? extends RealLocalizable> received = GeomUtils.vertices(test);
    assertEquals("Number of polygon points differs.", expected.size(), received.size());
    for (int i = 0; i < contour.numVertices(); i++) {
        assertEquals("Polygon point " + i + " differs in x-coordinate.", expected.get(i).getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON);
        assertEquals("Polygon point " + i + " differs in y-coordinate.", expected.get(i).getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON);
    }
}
Also used : LabelRegionToPolygonConverter(net.imagej.ops.geom.geom2d.LabelRegionToPolygonConverter) Polygon2D(net.imglib2.roi.geom.real.Polygon2D) RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Example 13 with RealLocalizable

use of net.imglib2.RealLocalizable in project imagej-ops by imagej.

the class PolygonFeatureTests method smallesEnclosingRectangle.

@Test
public void smallesEnclosingRectangle() {
    // ground truth verified with matlab
    final List<? extends RealLocalizable> received = GeomUtils.vertices(((Polygon2D) ops.run(DefaultSmallestEnclosingRectangle.class, contour)));
    final RealPoint[] expected = new RealPoint[] { new RealPoint(37.229184188393, -0.006307821699), new RealPoint(-14.757779646762, 27.800672834315), new RealPoint(31.725820016821, 114.704793944491), new RealPoint(83.712783851976, 86.897813288478) };
    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) DefaultSmallestEnclosingRectangle(net.imagej.ops.geom.geom2d.DefaultSmallestEnclosingRectangle) RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Example 14 with RealLocalizable

use of net.imglib2.RealLocalizable in project imagej-ops by imagej.

the class PolygonFeatureTests method convexHull2D.

@Test
public void convexHull2D() {
    // ground truth computed with matlab
    final Polygon2D test = (Polygon2D) ops.run(DefaultConvexHull2D.class, contour);
    final List<? extends RealLocalizable> received = GeomUtils.vertices(test);
    final RealPoint[] expected = new RealPoint[] { new RealPoint(1, 30), new RealPoint(2, 29), new RealPoint(26, 6), new RealPoint(31, 6), new RealPoint(42, 9), new RealPoint(49, 22), new RealPoint(72, 65), new RealPoint(78, 77), new RealPoint(48, 106), new RealPoint(42, 109), new RealPoint(34, 109), new RealPoint(28, 106), new RealPoint(26, 104), new RealPoint(23, 98) };
    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) DefaultConvexHull2D(net.imagej.ops.geom.geom2d.DefaultConvexHull2D) Polygon2D(net.imglib2.roi.geom.real.Polygon2D) RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Example 15 with RealLocalizable

use of net.imglib2.RealLocalizable in project imagej-ops by imagej.

the class PolygonFeatureTests method contour.

@Test
public void contour() {
    // ground truth computed with matlab
    final Polygon2D test = (Polygon2D) ops.run(DefaultContour.class, ROI, true);
    final List<? extends RealLocalizable> expected = GeomUtils.vertices(contour);
    final List<? extends RealLocalizable> received = GeomUtils.vertices(test);
    assertEquals("Number of polygon points differs.", expected.size(), received.size());
    for (int i = 0; i < contour.numVertices(); i++) {
        assertEquals("Polygon point " + i + " differs in x-coordinate.", expected.get(i).getDoublePosition(0), received.get(i).getDoublePosition(0), EPSILON);
        assertEquals("Polygon point " + i + " differs in y-coordinate.", expected.get(i).getDoublePosition(1), received.get(i).getDoublePosition(1), EPSILON);
    }
}
Also used : DefaultContour(net.imagej.ops.geom.geom2d.DefaultContour) Polygon2D(net.imglib2.roi.geom.real.Polygon2D) RealPoint(net.imglib2.RealPoint) Test(org.junit.Test) AbstractFeatureTest(net.imagej.ops.features.AbstractFeatureTest)

Aggregations

RealLocalizable (net.imglib2.RealLocalizable)21 RealPoint (net.imglib2.RealPoint)15 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)6 DefaultMesh (net.imagej.ops.geom.geom3d.mesh.DefaultMesh)6 Vertex (net.imagej.ops.geom.geom3d.mesh.Vertex)6 Polygon2D (net.imglib2.roi.geom.real.Polygon2D)6 ArrayList (java.util.ArrayList)5 AbstractFeatureTest (net.imagej.ops.features.AbstractFeatureTest)5 AbstractOpTest (net.imagej.ops.AbstractOpTest)4 DefaultConvexHull3D (net.imagej.ops.geom.geom3d.DefaultConvexHull3D)4 TriangularFacet (net.imagej.ops.geom.geom3d.mesh.TriangularFacet)4 DefaultWritablePolygon2D (net.imglib2.roi.geom.real.DefaultWritablePolygon2D)4 ValuePair (net.imglib2.util.ValuePair)3 Facet (net.imagej.ops.geom.geom3d.mesh.Facet)2 Vector3D (org.apache.commons.math3.geometry.euclidean.threed.Vector3D)2 Random (java.util.Random)1 DefaultBoundingBox (net.imagej.ops.geom.geom2d.DefaultBoundingBox)1 DefaultContour (net.imagej.ops.geom.geom2d.DefaultContour)1 DefaultConvexHull2D (net.imagej.ops.geom.geom2d.DefaultConvexHull2D)1