MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / orientation_ras_lps

Function orientation_ras_lps

monai/data/utils.py:1485–1498  ·  view source on GitHub ↗

Convert the ``affine`` between the `RAS` and `LPS` orientation by flipping the first two spatial dimensions. Args: affine: a 2D affine matrix.

(affine: NdarrayTensor)

Source from the content-addressed store, hash-verified

1483
1484
1485def orientation_ras_lps(affine: NdarrayTensor) -> NdarrayTensor:
1486 """
1487 Convert the ``affine`` between the `RAS` and `LPS` orientation
1488 by flipping the first two spatial dimensions.
1489
1490 Args:
1491 affine: a 2D affine matrix.
1492 """
1493 sr = max(affine.shape[0] - 1, 1) # spatial rank is at least 1
1494 flip_d = [[-1, 1], [-1, -1, 1], [-1, -1, 1, 1]]
1495 flip_diag = flip_d[min(sr - 1, 2)] + [1] * (sr - 3)
1496 if isinstance(affine, torch.Tensor):
1497 return torch.diag(torch.as_tensor(flip_diag).to(affine)) @ affine # type: ignore
1498 return np.diag(flip_diag).astype(affine.dtype) @ affine # type: ignore
1499
1500
1501def remove_keys(data: dict, keys: list[str]) -> None:

Callers 9

extract_affineMethod · 0.90
_get_affineMethod · 0.90
_get_affineMethod · 0.90
_switch_lps_rasMethod · 0.90
create_backend_objMethod · 0.90
metatensor_to_itk_imageFunction · 0.90
_compute_final_affineMethod · 0.90
transform_coordinatesMethod · 0.90
test_ras_to_lpsMethod · 0.90

Calls 4

maxFunction · 0.85
minFunction · 0.85
as_tensorMethod · 0.80
astypeMethod · 0.80

Tested by 1

test_ras_to_lpsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…