Search in sources :

Example 16 with Pnt2d

use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.

the class HoughLineTest method test0.

@Test
public void test0() {
    // example from CV lecture notes
    Pnt2d xRef = PntInt.from(90, 60);
    AlgebraicLine h12 = AlgebraicLine.from(p1, p2);
    HoughLine L12 = new HoughLine(h12, xRef.getX(), xRef.getY(), 0);
    Assert.assertEquals(0.0, L12.getDistance(p1), 1E-6);
    Assert.assertEquals(0.0, L12.getDistance(p2), 1E-6);
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) AlgebraicLine(imagingbook.pub.geometry.lines.AlgebraicLine) Test(org.junit.Test)

Example 17 with Pnt2d

use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.

the class HessianLineTest method test3.

@Test
public void test3() {
    HessianLine l12 = HessianLine.fromPoints(p1, p2);
    Pnt2d x0 = l12.getClosestLinePoint(p3);
    // x0 is actually ON the line
    Assert.assertEquals(0.0, l12.getDistance(x0), 1E-6);
    // distance (p3,x0) is shortest
    Assert.assertEquals(p3.distance(x0), Math.abs(l12.getDistance(p3)), 1E-6);
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) Test(org.junit.Test)

Example 18 with Pnt2d

use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.

the class RoiUtils method getPolygonPointsInts.

/**
 * Retrieves the outline of the specified ROI as an
 * array of {@link Pnt2d} points with {@code int}
 * coordinates. Note that unless the ROI is of type
 * {@link PolygonRoi} or {@link PointRoi} only the corner points of the
 * bounding box are returned.
 * Interpolated contour points are returned for a instance of {@link OvalRoi}.
 *
 * @param roi the ROI
 * @return the ROI's polygon coordinates
 */
public static Pnt2d[] getPolygonPointsInts(Roi roi) {
    Polygon pgn = roi.getPolygon();
    Pnt2d[] pts = new Pnt2d[pgn.npoints];
    for (int i = 0; i < pgn.npoints; i++) {
        pts[i] = Pnt2d.PntInt.from(pgn.xpoints[i], pgn.ypoints[i]);
    }
    return pts;
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) Polygon(java.awt.Polygon) FloatPolygon(ij.process.FloatPolygon)

Example 19 with Pnt2d

use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.

the class Utils method makeOuterTriangle.

/**
 * Creates a 2D triangle that is sufficiently large to be used as
 * an outer triangle for the Delaunay triangulation of the given
 * point set.
 * @param points the 2D point set
 * @return a triangle as an array of 3 points
 */
public static Pnt2d[] makeOuterTriangle(Collection<? extends Pnt2d> points) {
    double xmin = Double.POSITIVE_INFINITY;
    double xmax = Double.NEGATIVE_INFINITY;
    double ymin = xmin;
    double ymax = xmax;
    for (Pnt2d p : points) {
        double x = p.getX();
        double y = p.getY();
        xmin = Math.min(x, xmin);
        xmax = Math.max(x, xmax);
        ymin = Math.min(y, ymin);
        ymax = Math.max(y, ymax);
    }
    return makeOuterTriangle(xmin, xmax, ymin, ymax);
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 20 with Pnt2d

use of imagingbook.pub.geometry.basic.Pnt2d in project imagingbook-common by imagingbook.

the class FourierDescriptorFromPolygon method getRoiPoints.

static Pnt2d[] getRoiPoints(Roi roi) {
    Polygon poly = roi.getPolygon();
    int[] xp = poly.xpoints;
    int[] yp = poly.ypoints;
    // copy vertices for all non-zero-length polygon segments:
    List<Pnt2d> points = new ArrayList<>(xp.length);
    points.add(PntInt.from(xp[0], yp[0]));
    int last = 0;
    for (int i = 1; i < xp.length; i++) {
        if (xp[last] != xp[i] || yp[last] != yp[i]) {
            points.add(PntInt.from(xp[i], yp[i]));
            last = i;
        }
    }
    // remove last point if the closing segment has zero length:
    if (xp[last] == xp[0] && yp[last] == yp[0]) {
        points.remove(last);
    }
    return points.toArray(new Pnt2d[0]);
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) ArrayList(java.util.ArrayList) Polygon(java.awt.Polygon)

Aggregations

Pnt2d (imagingbook.pub.geometry.basic.Pnt2d)39 Test (org.junit.Test)6 ProjectiveMapping2D (imagingbook.pub.geometry.mappings.linear.ProjectiveMapping2D)5 RealMatrix (org.apache.commons.math3.linear.RealMatrix)5 FloatPolygon (ij.process.FloatPolygon)2 Polygon (java.awt.Polygon)2 ArrayList (java.util.ArrayList)2 ImageProcessor (ij.process.ImageProcessor)1 ImageAccessor (imagingbook.lib.image.access.ImageAccessor)1 PntInt (imagingbook.pub.geometry.basic.Pnt2d.PntInt)1 AlgebraicLine (imagingbook.pub.geometry.lines.AlgebraicLine)1 Mapping2D (imagingbook.pub.geometry.mappings.Mapping2D)1 LinearMapping2D (imagingbook.pub.geometry.mappings.linear.LinearMapping2D)1 Point (java.awt.Point)1 Path2D (java.awt.geom.Path2D)1 ArrayRealVector (org.apache.commons.math3.linear.ArrayRealVector)1 RealVector (org.apache.commons.math3.linear.RealVector)1