Created
April 30, 2018 15:34
-
-
Save jmswaney/f9e336f28f5de9fa208dff8f91d1012a to your computer and use it in GitHub Desktop.
Basic 3D TPS warp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def coord_mapping(fixed_coords, c, matches_stationary, smoothing): | |
"""Apply 3D thin-plate spline mapping to fixed_coords. | |
The RBF keypoints are given in matches_stationary. Smoothing is a | |
surface energy regularization parameter. | |
Parameters | |
---------- | |
fixed_coords : ndarray | |
(N, 3) array of points to warp | |
c : ndarray | |
(M, 3) array of spline coefficients for z, y, and x axes | |
matches_stationary : ndarray | |
(M, 3) array of keypoint coordinates | |
smoothing : float | |
surface energy regularization parameter | |
Returns | |
------- | |
moving_coords : ndarray | |
(N, 3) array of warped points | |
""" | |
nb_pts = fixed_coords.shape[0] | |
dist = scipy.spatial.distance.cdist(fixed_coords, matches_stationary) | |
nb_matches = matches_stationary.shape[0] | |
T = np.zeros((nb_pts, 4+nb_matches)) | |
T[:, :4] = np.hstack([np.ones((nb_pts,1)), fixed_coords]) | |
T[:, 4:] = dist + nb_matches*smoothing | |
moving_coords = T.dot(c) | |
return moving_coords |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment