Convert the ``affine`` between the `RAS` and `LPS` orientation by flipping the first two spatial dimensions. Args: affine: a 2D affine matrix.
(affine: NdarrayTensor)
| 1483 | |
| 1484 | |
| 1485 | def 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 | |
| 1501 | def remove_keys(data: dict, keys: list[str]) -> None: |
searching dependent graphs…