MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / affine_transform

Function affine_transform

detrsmpl/data/datasets/pipelines/transforms.py:73–91  ·  view source on GitHub ↗

Apply an affine transformation to the points. Args: pt (np.ndarray): a 2 dimensional point to be transformed trans_mat (np.ndarray): 2x3 matrix of an affine transform Returns: np.ndarray: Transformed points.

(pt, trans_mat)

Source from the content-addressed store, hash-verified

71
72
73def affine_transform(pt, trans_mat):
74 """Apply an affine transformation to the points.
75
76 Args:
77 pt (np.ndarray): a 2 dimensional point to be transformed
78 trans_mat (np.ndarray): 2x3 matrix of an affine transform
79 Returns:
80 np.ndarray: Transformed points.
81 """
82 if pt.ndim == 2:
83 new_pt = np.einsum('ij,mj->im', pt, trans_mat)
84 elif pt.ndim == 3:
85 new_pt = np.einsum('nij,mj->nim', pt, trans_mat)
86 else:
87 msg = f'Expected pt to have ndim of 2 or 3, but get {pt.ndim} '
88 raise ValueError(msg)
89 # new_pt = np.array(trans_mat) @ np.array([pt[0], pt[1], 1.])
90
91 return new_pt
92
93
94def _get_3rd_point(a, b):

Callers 4

__call__Method · 0.85
__call__Method · 0.85
transform_predsFunction · 0.85
__call__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected