MCPcopy
hub / github.com/mne-tools/mne-python / fit_matched_points

Function fit_matched_points

mne/coreg.py:363–466  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

361
362# XXX this function should be moved out of coreg as used elsewhere
363def 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})"

Callers 6

test_fit_matched_pointsFunction · 0.90
coregister_fiducialsFunction · 0.85
fit_fiducialsMethod · 0.85
fit_icpMethod · 0.85
_estimate_talxfm_rigidFunction · 0.85
_set_dig_kitFunction · 0.85

Calls 6

_fit_matched_pointsFunction · 0.85
_quat_to_eulerFunction · 0.85
_generic_fitFunction · 0.85
_trans_from_paramsFunction · 0.85
sqrtMethod · 0.80
sumMethod · 0.45

Tested by 1

test_fit_matched_pointsFunction · 0.72