Passed
Pull Request — master (#417)
by Fernando
01:22
created

TestInvertibility.test_ignore_intensity()   A

Complexity

Conditions 3

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
import warnings
2
3
from torchio.transforms.intensity_transform import IntensityTransform
4
from ..utils import TorchioTestCase
5
6
7
class TestInvertibility(TorchioTestCase):
8
9
    def test_all_random_transforms(self):
10
        transform = self.get_large_composed_transform()
11
        # Remove RandomLabelsToImage as it will add a new image to the subject
12
        for t in transform.transforms:
13
            if t.name == 'RandomLabelsToImage':
14
                transform.transforms.remove(t)
15
                break
16
        # Ignore elastic deformation and gamma warnings during execution
17
        # Ignore some transforms not invertible
18
        with warnings.catch_warnings():
19
            warnings.simplefilter('ignore', RuntimeWarning)
20
            transformed = transform(self.sample_subject)
21
            inverting_transform = transformed.get_inverse_transform()
22
            transformed_back = inverting_transform(transformed)
23
        self.assertEqual(
24
            transformed.t1.shape,
25
            transformed_back.t1.shape,
26
        )
27
        self.assertTensorEqual(
28
            transformed.label.affine,
29
            transformed_back.label.affine,
30
        )
31
32
    def test_ignore_intensity(self):
33
        composed = self.get_large_composed_transform()
34
        with warnings.catch_warnings():
35
            warnings.simplefilter('ignore', RuntimeWarning)
36
            transformed = composed(self.sample_subject)
37
        inverse_transform = transformed.get_inverse_transform(warn=False)
38
        for transform in inverse_transform:
39
            assert not isinstance(transform, IntensityTransform)
40