Search in sources :

Example 31 with Pnt2d

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

the class ParametricLine 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);
    ParametricLine pl = ParametricLine.from(al1);
    System.out.println("pl = " + pl);
    AlgebraicLine al2 = AlgebraicLine.from(pl);
    System.out.println("al2 = " + al2);
    System.out.println("al1 = al2 ? " + al1.equals(al2));
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 32 with Pnt2d

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

the class ProcrustesFit method makeDataMatrix.

private RealMatrix makeDataMatrix(Pnt2d[] points, double[] meanX) {
    RealMatrix M = MatrixUtils.createRealMatrix(2, points.length);
    RealVector mean = MatrixUtils.createRealVector(meanX);
    int i = 0;
    for (Pnt2d p : points) {
        RealVector cv = p.toRealVector();
        // RealVector cv = MatrixUtils.createRealVector(p.toDoubleArray());
        if (meanX != null) {
            cv = cv.subtract(mean);
        }
        M.setColumnVector(i, cv);
        i++;
    }
    return M;
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) RealMatrix(org.apache.commons.math3.linear.RealMatrix) RealVector(org.apache.commons.math3.linear.RealVector) ArrayRealVector(org.apache.commons.math3.linear.ArrayRealVector)

Example 33 with Pnt2d

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

the class ProcrustesFit method getMeanVec.

private double[] getMeanVec(Pnt2d[] points) {
    double sumX = 0;
    double sumY = 0;
    for (Pnt2d p : points) {
        sumX = sumX + p.getX();
        sumY = sumY + p.getY();
    }
    return new double[] { sumX / points.length, sumY / points.length };
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 34 with Pnt2d

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

the class ProjectiveMapping2D method main.

// -----------------------------------------------------------------
/**
 * For testing only.
 * @param args ignored
 */
public static void main(String[] args) {
    PrintPrecision.set(6);
    // book example:
    Pnt2d[] P = { PntDouble.from(2, 5), PntDouble.from(4, 6), PntDouble.from(7, 9), PntDouble.from(5, 9), // 5 points, overdetermined!
    PntDouble.from(5.2, 9.1) };
    Pnt2d[] Q = { PntDouble.from(4, 3), PntDouble.from(5, 2), PntDouble.from(9, 3), PntDouble.from(7, 5), // 5 points, overdetermined!
    PntDouble.from(7, 4.9) };
    ProjectiveMapping2D pm = ProjectiveMapping2D.fromPoints(P, Q);
    System.out.println("\nprojective mapping = \n" + pm.toString());
    for (int i = 0; i < P.length; i++) {
        Pnt2d Bi = pm.applyTo(P[i]);
        System.out.println(P[i].toString() + " -> " + Bi.toString());
    }
    System.out.println("pm is of class " + pm.getClass().getName());
    ProjectiveMapping2D pmi = pm.getInverse();
    pmi = pmi.normalize();
    System.out.println("\ninverse projective mapping (normalized) = \n" + pmi.toString());
    for (int i = 0; i < Q.length; i++) {
        Pnt2d Ai = pmi.applyTo(Q[i]);
        System.out.println(Q[i].toString() + " -> " + Ai.toString());
    }
    ProjectiveMapping2D testId = pm.concat(pmi);
    System.out.println("\ntest: should be a scaled identity matrix: = \n" + testId.toString());
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 35 with Pnt2d

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

the class LinearFit2D method calculateError.

public default double calculateError(Pnt2d[] P, Pnt2d[] Q, RealMatrix A) {
    final int m = Math.min(P.length, Q.length);
    LinearMapping2D map = new LinearMapping2D(A.getData());
    double errSum = 0;
    for (int i = 0; i < m; i++) {
        Pnt2d p = P[i];
        Pnt2d q = Q[i];
        Pnt2d pp = map.applyTo(p);
        double e = q.distance(pp);
        errSum = errSum + e * e;
    }
    return Math.sqrt(errSum);
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) LinearMapping2D(imagingbook.pub.geometry.mappings.linear.LinearMapping2D)

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