| Total Complexity | 4 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from ....data.subject import Subject |
||
| 2 | from ...spatial_transform import SpatialTransform |
||
| 3 | from .to_orientation import ToOrientation |
||
| 4 | |||
| 5 | |||
| 6 | class Transpose(SpatialTransform): |
||
| 7 | """Swap the first and last spatial dimensions of the image, respecting metadata. |
||
| 8 | |||
| 9 | Example: |
||
| 10 | |||
| 11 | >>> import torchio as tio |
||
| 12 | >>> image = tio.datasets.FPG().t1 |
||
| 13 | >>> image |
||
| 14 | ScalarImage(shape: (1, 256, 256, 176); spacing: (1.00, 1.00, 1.00); orientation: PIR+; path: "/home/fernando/.cache/torchio/fpg/t1.nii.gz") |
||
| 15 | >>> transpose = tio.Transpose() |
||
| 16 | >>> transposed = transpose(image) |
||
| 17 | >>> transposed |
||
| 18 | """ |
||
| 19 | |||
| 20 | def apply_transform(self, subject: Subject) -> Subject: |
||
| 21 | for image in self.get_images(subject): |
||
| 22 | transform = ToOrientation(image.orientation_str[::-1]) |
||
| 23 | transposed = transform(image) |
||
| 24 | image.set_data(transposed.data) |
||
| 25 | image.affine = transposed.affine |
||
| 26 | return subject |
||
| 27 | |||
| 28 | def is_invertible(self): |
||
| 29 | return True |
||
| 30 | |||
| 31 | def inverse(self): |
||
| 32 | return self |
||
| 33 |