Search in sources :

Example 1 with LabelRegionToPolygonConverter

use of net.imagej.ops.geom.geom2d.LabelRegionToPolygonConverter 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)

Aggregations

AbstractFeatureTest (net.imagej.ops.features.AbstractFeatureTest)1 LabelRegionToPolygonConverter (net.imagej.ops.geom.geom2d.LabelRegionToPolygonConverter)1 RealPoint (net.imglib2.RealPoint)1 Polygon2D (net.imglib2.roi.geom.real.Polygon2D)1 Test (org.junit.Test)1