| Total Complexity | 12 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import torch |
||
| 2 | from torchio import ScalarImage, RandomAnisotropy |
||
| 3 | from ...utils import TorchioTestCase |
||
| 4 | |||
| 5 | |||
| 6 | class TestRandomAnisotropy(TorchioTestCase): |
||
| 7 | """Tests for `RandomAnisotropy`.""" |
||
| 8 | |||
| 9 | def test_downsample(self): |
||
| 10 | transform = RandomAnisotropy( |
||
| 11 | axes=1, |
||
| 12 | downsampling=(2., 2.) |
||
| 13 | ) |
||
| 14 | transformed = transform(self.sample_subject) |
||
| 15 | self.assertEqual(self.sample_subject.spacing[1], transformed.spacing[1]) |
||
| 16 | |||
| 17 | def test_out_of_range_axis(self): |
||
| 18 | with self.assertRaises(ValueError): |
||
| 19 | RandomAnisotropy(axes=3) |
||
| 20 | |||
| 21 | def test_out_of_range_axis_in_tuple(self): |
||
| 22 | with self.assertRaises(ValueError): |
||
| 23 | RandomAnisotropy(axes=(0, -1, 2)) |
||
| 24 | |||
| 25 | def test_wrong_axes_type(self): |
||
| 26 | with self.assertRaises(ValueError): |
||
| 27 | RandomAnisotropy(axes='wrong') |
||
| 28 | |||
| 29 | def test_wrong_downsampling_type(self): |
||
| 30 | with self.assertRaises(ValueError): |
||
| 31 | RandomAnisotropy(downsampling='wrong') |
||
| 32 | |||
| 33 | def test_below_one_downsampling(self): |
||
| 34 | with self.assertRaises(ValueError): |
||
| 35 | RandomAnisotropy(downsampling=0.2) |
||
| 36 | |||
| 37 | def test_2d_rgb(self): |
||
| 38 | image = ScalarImage(tensor=torch.rand(3, 4, 5, 6)) |
||
| 39 | RandomAnisotropy()(image) |
||
| 40 |