Search in sources :

Example 11 with Pnt2d

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

the class HomographyEstimator method runTestDLT.

private static void runTestDLT(HomographyEstimator he, Pnt2d[] pntsA, Pnt2d[] pntsB) {
    RealMatrix Hest = he.getHomography(pntsA, pntsB);
    System.out.println("H (estim.) = ");
    System.out.println(Matrix.toString(Hest.getData()));
    Pnt2d[] pntsC = new Pnt2d[pntsA.length];
    for (int i = 0; i < pntsA.length; i++) {
        pntsC[i] = mapPoint(Hest, pntsA[i]);
    }
    System.out.println("\nPoints mapped:");
    double sumDist2 = 0;
    double maxDist2 = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < pntsA.length; i++) {
        Pnt2d a = pntsA[i];
        Pnt2d b = pntsB[i];
        Pnt2d c = pntsC[i];
        double dist2 = b.distanceSq(c);
        sumDist2 += dist2;
        maxDist2 = Math.max(maxDist2, dist2);
        System.out.format("(%.3f, %.3f) -> (%.3f, %.3f) d=%.4f\n", a.getX(), a.getY(), c.getX(), c.getY(), dist2);
    }
    System.out.format("\nTotal error = %.2f\n", Math.sqrt(sumDist2));
    System.out.format("Max. dist = %.2f\n", Math.sqrt(maxDist2));
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Example 12 with Pnt2d

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

the class SlopeInterceptLine method main.

// --------------------------------------------------
public static void main(String[] args) {
    Pnt2d p1 = Pnt2d.from(1, 2);
    Pnt2d p2 = Pnt2d.from(4, 3);
    AlgebraicLine al1 = AlgebraicLine.from(p1, p2);
    System.out.println("al1 = " + al1);
    SlopeInterceptLine sl = SlopeInterceptLine.from(al1);
    System.out.println("sl = " + sl);
    AlgebraicLine al2 = AlgebraicLine.from(sl);
    System.out.println("al2 = " + al2);
    System.out.println("al1 = al2 ? " + al1.equals(al2));
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 13 with Pnt2d

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

the class Contour method isClosed.

/**
 * Checks if this contour is closed w.r.t. the specified
 * {@link NeighborhoodType2D}, i.e., if the last and the first
 * contour point are "connected".
 *
 * @param nht the (@link NeighborhoodType}.
 * @return true if the contour is closed.
 */
public boolean isClosed(NeighborhoodType2D nht) {
    Pnt2d[] pnts = this.getPointArray();
    if (pnts.length < 2)
        return true;
    Pnt2d p1 = pnts[pnts.length - 1];
    Pnt2d p2 = pnts[0];
    // N4: max 1, N8: max 2
    double d2 = p1.distanceSq(p2);
    if (nht == NeighborhoodType2D.N4 && d2 <= 1)
        return true;
    if (nht == NeighborhoodType2D.N8 && d2 <= 2)
        return true;
    return false;
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 14 with Pnt2d

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

the class EdgeTrace method main.

// ---------------------------------------------------------
public static void main(String[] args) {
    EdgeTrace trace = new EdgeTrace();
    trace.addPoint(PntInt.from(1, 2));
    trace.addPoint(PntInt.from(3, 4));
    trace.addPoint(PntInt.from(5, 6));
    for (Pnt2d p : trace) {
        System.out.println(p);
    }
    System.out.println();
    trace.addPoint(PntInt.from(7, 8));
    for (PntInt p : trace.getPointArray()) {
        System.out.println(p);
    }
    System.out.println();
    for (Point p : trace.getAwtPoints()) {
        System.out.println(p);
    }
    System.out.println(trace.getPoint(3));
    System.out.println(trace.getPoint(4));
    PntInt[] copy = Arrays.copyOfRange(trace.getPointArray(), 0, 7);
    System.out.println(copy.length);
    for (PntInt p : copy) {
        System.out.println(p);
    }
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) Point(java.awt.Point) PntInt(imagingbook.pub.geometry.basic.Pnt2d.PntInt)

Example 15 with Pnt2d

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

the class HoughLineTest method test2.

@Test
public void test2() {
    HoughLine l12 = HoughLine.fromPoints(p1, p2, pRef, 2);
    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)

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