navis.transforms.MovingLeastSquaresTransform¶
- class navis.transforms.MovingLeastSquaresTransform(landmarks_source, landmarks_target, direction='forward')[source]¶
Moving Least Squares transforms of 3D spatial data.
Uses the molesq library, which packages the implementation by Casey Schneider-Mizell of the affine algorithm published in Schaefer et al. 2006.
- Parameters:
landmarks_source (np.ndarray) – Source landmarks as x/y/z coordinates.
landmarks_target (np.ndarray) – Target landmarks as x/y/z coordinates.
direction (str) – ‘forward’ (default) or ‘inverse’ (treat the target as the source and vice versa)
Examples
>>> from navis import transforms >>> import numpy as np >>> # Generate some mock landmarks >>> src = np.array([[0, 0, 0], [10, 10, 10], [100, 100, 100], [80, 10, 30]]) >>> trg = np.array([[1, 15, 5], [9, 18, 21], [80, 99, 120], [5, 10, 80]]) >>> tr = transforms.MovingLeastSquaresTransform(src, trg) >>> points = np.array([[0, 0, 0], [50, 50, 50]]) >>> tr.xform(points) array([[ 1. , 15. , 5. ], [17.56361725, 43.32071504, 59.3147564 ]])
- __init__(landmarks_source, landmarks_target, direction='forward')[source]¶
Moving Least Squares transforms of 3D spatial data.
Uses the molesq library, which packages the implementation by Casey Schneider-Mizell of the affine algorithm published in Schaefer et al. 2006.
- Parameters:
landmarks_source (np.ndarray) – Source landmarks as x/y/z coordinates.
landmarks_target (np.ndarray) – Target landmarks as x/y/z coordinates.
direction (str) – ‘forward’ (default) or ‘inverse’ (treat the target as the source and vice versa)
Examples
>>> from navis import transforms >>> import numpy as np >>> # Generate some mock landmarks >>> src = np.array([[0, 0, 0], [10, 10, 10], [100, 100, 100], [80, 10, 30]]) >>> trg = np.array([[1, 15, 5], [9, 18, 21], [80, 99, 120], [5, 10, 80]]) >>> tr = transforms.MovingLeastSquaresTransform(src, trg) >>> points = np.array([[0, 0, 0], [50, 50, 50]]) >>> tr.xform(points) array([[ 1. , 15. , 5. ], [17.56361725, 43.32071504, 59.3147564 ]])
Methods
__init__
(landmarks_source, landmarks_target)Moving Least Squares transforms of 3D spatial data.
append
(other)Append another transform to this one.
check_if_possible
([on_error])Test if running the transform is possible.
copy
()Make a copy
xform
(points)Transform points.