Skip to content

Commit fa47ff7

Browse files
committed
re added the reduntent function from claude.
1 parent 62ba318 commit fa47ff7

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

TPTBox/core/nii_poi_abstract.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,18 @@ def global_to_local(self, x: COORDINATE, itk=False) -> tuple:
493493
a = self.rotation.T @ (x_ - self.origin) / np.array(self.zoom)
494494
return tuple(round(float(v), 7) for v in a)
495495

496+
def global_to_local_arr(self, coords: np.ndarray, itk=False) -> np.ndarray:
497+
"""Vectorized :meth:`global_to_local` for an ``(N, 3)`` array of world coordinates.
498+
499+
Equivalent to applying ``global_to_local`` to each row but in a single batched
500+
inverse-affine matmul.
501+
"""
502+
a = (np.asarray(coords, dtype=float) - np.asarray(self.origin)) @ np.asarray(self.rotation) / np.asarray(self.zoom)
503+
if itk:
504+
a[:, 0] *= -1
505+
a[:, 1] *= -1
506+
return np.round(a, 7)
507+
496508
def local_to_global(self, x: COORDINATE | np.ndarray, itk=False) -> tuple:
497509
"""Convert voxel (local) coordinates to world (RAS/LPS) coordinates.
498510

0 commit comments

Comments
 (0)