| Total Complexity | 2 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import numpy as np |
||
| 2 | from numpy.testing import assert_array_equal |
||
| 3 | from torchio.transforms import ToCanonical |
||
| 4 | from ...utils import TorchioTestCase |
||
| 5 | |||
| 6 | |||
| 7 | class TestToCanonical(TorchioTestCase): |
||
| 8 | """Tests for :py:class:`ToCanonical` class.""" |
||
| 9 | |||
| 10 | def test_no_changes(self): |
||
| 11 | transform = ToCanonical() |
||
| 12 | transformed = transform(self.sample) |
||
| 13 | assert_array_equal(transformed.t1.data, self.sample.t1.data) |
||
| 14 | assert_array_equal(transformed.t1.affine, self.sample.t1.affine) |
||
| 15 | |||
| 16 | def test_LAS_to_RAS(self): |
||
| 17 | self.sample.t1.affine[0, 0] = -1 # Change orientation to 'LAS' |
||
| 18 | transform = ToCanonical() |
||
| 19 | transformed = transform(self.sample) |
||
| 20 | self.assertEqual(transformed.t1.orientation, ('R', 'A', 'S')) |
||
| 21 | assert_array_equal( |
||
| 22 | transformed.t1.data, |
||
| 23 | self.sample.t1.data.numpy()[:, ::-1, :, :] |
||
| 24 | ) |
||
| 25 | |||
| 26 | fixture = np.eye(4) |
||
| 27 | fixture[0, -1] = -self.sample.t1.spatial_shape[0] + 1 |
||
| 28 | assert_array_equal(transformed.t1.affine, fixture) |
||
| 29 |