| Total Complexity | 6 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import torch |
||
| 2 | import numpy as np |
||
| 3 | import torchio as tio |
||
| 4 | from ...utils import TorchioTestCase |
||
| 5 | |||
| 6 | |||
| 7 | class TestResize(TorchioTestCase): |
||
| 8 | """Tests for `Resize`.""" |
||
| 9 | def test_one_dim(self): |
||
| 10 | target_shape = 5 |
||
| 11 | transform = tio.Resize(target_shape) |
||
| 12 | transformed = transform(self.sample_subject) |
||
| 13 | for image in transformed.get_images(intensity_only=False): |
||
| 14 | self.assertEqual(image.spatial_shape, 3 * (target_shape,)) |
||
| 15 | |||
| 16 | def test_all_dims(self): |
||
| 17 | target_shape = 11, 6, 7 |
||
| 18 | transform = tio.Resize(target_shape) |
||
| 19 | transformed = transform(self.sample_subject) |
||
| 20 | for image in transformed.get_images(intensity_only=False): |
||
| 21 | self.assertEqual(image.spatial_shape, target_shape) |
||
| 22 | |||
| 23 | def test_fix_shape(self): |
||
| 24 | # We use values that are known to need cropping |
||
| 25 | tensor = torch.rand(1, 8, 180, 320) |
||
| 26 | affine = np.diag((5, 1, 1, 1)) |
||
| 27 | im = tio.ScalarImage(tensor=tensor, affine=affine) |
||
| 28 | target = 12 |
||
| 29 | with self.assertWarns(UserWarning): |
||
| 30 | result = tio.Resize(target)(im) |
||
| 31 | self.assertEqual(result.spatial_shape, 3 * (target,)) |
||
| 32 |