Search in sources :

Example 26 with Pnt2d

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

the class Translation2DTest method testInvert.

@Test
public void testInvert() {
    Translation2D m = new Translation2D(-1.5, 19.0);
    Pnt2d p = Pnt2d.from(3.5, -17);
    Pnt2d q = m.applyTo(p);
    Pnt2d pp = m.getInverse().applyTo(q);
    Assert.assertArrayEquals(p.toDoubleArray(), pp.toDoubleArray(), 1E-6);
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d) Test(org.junit.Test)

Example 27 with Pnt2d

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

the class BilinearMapping2D method main.

// ------------------------------------------------------------------------
/**
 * For testing only.
 * @param args ignored
 */
public static void main(String[] args) {
    Pnt2d[] P = { PntInt.from(2, 5), PntInt.from(4, 6), PntInt.from(7, 9), PntInt.from(5, 9) };
    Pnt2d[] Q = { PntInt.from(4, 3), PntInt.from(5, 2), PntInt.from(9, 3), PntInt.from(7, 5) };
    BilinearMapping2D bm = fromPoints(P, Q);
    System.out.println("\nbilinear mapping = \n" + bm.toString());
    for (int i = 0; i < P.length; i++) {
        Pnt2d Qi = bm.applyTo(P[i]);
        System.out.println(P[i].toString() + " -> " + Qi.toString());
    }
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 28 with Pnt2d

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

the class Moments2D method centralMoment.

public static double centralMoment(Iterable<Pnt2d> R, int p, int q) {
    // region area
    double m00 = ordinaryMoment(R, 0, 0);
    if (Arithmetic.isZero(m00)) {
        throw new RuntimeException("empty point set");
    }
    double xc = ordinaryMoment(R, 1, 0) / m00;
    double yc = ordinaryMoment(R, 0, 1) / m00;
    double mupq = 0.0;
    for (Pnt2d pnt : R) {
        mupq += Math.pow(pnt.getX() - xc, p) * Math.pow(pnt.getY() - yc, q);
    }
    return mupq;
}
Also used : Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 29 with Pnt2d

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

the class ImageExtractor method getMapping.

private ProjectiveMapping2D getMapping(int w, int h, Pnt2d[] sourcePnts) {
    Pnt2d[] targetPnts = { PntInt.from(0, 0), PntInt.from(w - 1, 0), PntInt.from(w - 1, h - 1), PntInt.from(0, h - 1) };
    ProjectiveMapping2D T = null;
    switch(sourcePnts.length) {
        case (3):
            T = AffineMapping2D.fromPoints(targetPnts, sourcePnts);
            break;
        case (4):
            T = ProjectiveMapping2D.fromPoints(targetPnts, sourcePnts);
            break;
        default:
            throw new IllegalArgumentException("wrong number of source points");
    }
    return T;
}
Also used : ProjectiveMapping2D(imagingbook.pub.geometry.mappings.linear.ProjectiveMapping2D) Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

Example 30 with Pnt2d

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

the class LucasKanadeInverseMatcher method iterateOnce.

@Override
public ProjectiveMapping2D iterateOnce(ProjectiveMapping2D Tp) {
    if (iteration < 0) {
        initializeMatch(Tp);
    }
    iteration = iteration + 1;
    // n-dim vector \delta_p = 0
    double[] dp = new double[n];
    sqrError = 0;
    // for all positions (u,v) in R do
    for (int u = 0; u < wR; u++) {
        for (int v = 0; v < hR; v++) {
            // get coordinate relative to center of R
            Pnt2d x = PntDouble.from(u - xc, v - yc);
            // warp I to I' (onto R)
            // warp from x -> x'
            Pnt2d xT = Tp.applyTo(x);
            // calculate pixel difference d for pos. (u,v)
            double d = I.getInterpolatedValue(xT.getX(), xT.getY()) - R.getf(u, v);
            sqrError = sqrError + d * d;
            // multiply the pixel difference d with the corresponding steepest descent image sx
            // and sum into dp:
            double[] sx = S[u][v];
            dp = Matrix.add(dp, Matrix.multiply(d, sx));
        }
    }
    // estimate the parameter difference vector qopt:
    double[] qopt = Matrix.multiply(Hi, dp);
    if (params.debug)
        IJ.log("qopt  = " + Matrix.toString(qopt));
    // measure the magnitude of the difference vector:
    qmag = Matrix.normL2squared(qopt);
    // Calculate the warp parameters p', such that T_p'(x) = T_p (T^-1_q (x), for any point x.
    ProjectiveMapping2D Tqopt = toProjectiveMap(qopt);
    ProjectiveMapping2D Tqopti = Tqopt.getInverse();
    return Tqopti.concat(Tp);
}
Also used : ProjectiveMapping2D(imagingbook.pub.geometry.mappings.linear.ProjectiveMapping2D) Pnt2d(imagingbook.pub.geometry.basic.Pnt2d)

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