use of imagingbook.pub.geometry.mappings.linear.ProjectiveMapping2D 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;
}
use of imagingbook.pub.geometry.mappings.linear.ProjectiveMapping2D 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);
}
Aggregations