Find a transform between matched sets of points. This minimizes the squared distance between two matching sets of points. Uses :func:`scipy.optimize.leastsq` to find a transformation involving a combination of rotation, translation, and scaling (in that order). Parameters ----
(
src_pts,
tgt_pts,
rotate=True,
translate=True,
scale=False,
tol=None,
x0=None,
out="trans",
weights=None,
)
| 361 | |
| 362 | # XXX this function should be moved out of coreg as used elsewhere |
| 363 | def fit_matched_points( |
| 364 | src_pts, |
| 365 | tgt_pts, |
| 366 | rotate=True, |
| 367 | translate=True, |
| 368 | scale=False, |
| 369 | tol=None, |
| 370 | x0=None, |
| 371 | out="trans", |
| 372 | weights=None, |
| 373 | ): |
| 374 | """Find a transform between matched sets of points. |
| 375 | |
| 376 | This minimizes the squared distance between two matching sets of points. |
| 377 | |
| 378 | Uses :func:`scipy.optimize.leastsq` to find a transformation involving |
| 379 | a combination of rotation, translation, and scaling (in that order). |
| 380 | |
| 381 | Parameters |
| 382 | ---------- |
| 383 | src_pts : array, shape = (n, 3) |
| 384 | Points to which the transform should be applied. |
| 385 | tgt_pts : array, shape = (n, 3) |
| 386 | Points to which src_pts should be fitted. Each point in tgt_pts should |
| 387 | correspond to the point in src_pts with the same index. |
| 388 | rotate : bool |
| 389 | Allow rotation of the ``src_pts``. |
| 390 | translate : bool |
| 391 | Allow translation of the ``src_pts``. |
| 392 | scale : bool |
| 393 | Number of scaling parameters. With False, points are not scaled. With |
| 394 | True, points are scaled by the same factor along all axes. |
| 395 | tol : scalar | None |
| 396 | The error tolerance. If the distance between any of the matched points |
| 397 | exceeds this value in the solution, a RuntimeError is raised. With |
| 398 | None, no error check is performed. |
| 399 | x0 : None | tuple |
| 400 | Initial values for the fit parameters. |
| 401 | out : 'params' | 'trans' |
| 402 | In what format to return the estimate: 'params' returns a tuple with |
| 403 | the fit parameters; 'trans' returns a transformation matrix of shape |
| 404 | (4, 4). |
| 405 | |
| 406 | Returns |
| 407 | ------- |
| 408 | trans : array, shape (4, 4) |
| 409 | Transformation that, if applied to src_pts, minimizes the squared |
| 410 | distance to tgt_pts. Only returned if out=='trans'. |
| 411 | params : array, shape (n_params, ) |
| 412 | A single tuple containing the rotation, translation, and scaling |
| 413 | parameters in that order (as applicable). |
| 414 | """ |
| 415 | src_pts = np.atleast_2d(src_pts) |
| 416 | tgt_pts = np.atleast_2d(tgt_pts) |
| 417 | if src_pts.shape != tgt_pts.shape: |
| 418 | raise ValueError( |
| 419 | "src_pts and tgt_pts must have same shape " |
| 420 | f"(got {src_pts.shape}, {tgt_pts.shape})" |