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)
| 71 | |
| 72 | |
| 73 | def 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 | |
| 94 | def _get_3rd_point(a, b): |
no outgoing calls
no test coverage detected