Passed
Push — master ( a5fd0f...582603 )
by Fernando
01:13
created

tests.transforms.augmentation.test_random_affine   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestRandomAffine.setUp() 0 5 1
A TestRandomAffine.test_rotation_image() 0 10 1
A TestRandomAffine.test_rotation_origin() 0 10 1
1
from torchio.transforms import RandomAffine
2
from ...utils import TorchioTestCase
3
4
5
class TestRandomAffine(TorchioTestCase):
6
    """Tests for `RandomAffine`."""
7
    def setUp(self):
8
        # Set image origin far from center
9
        super().setUp()
10
        affine = self.sample.t1.affine
11
        affine[:3, 3] = 1e5
12
13
    def test_rotation_image(self):
14
        # Rotation around image center
15
        transform = RandomAffine(
16
            degrees=(90, 90),
17
            default_pad_value=0,
18
            center='image',
19
        )
20
        transformed = transform(self.sample)
21
        total = transformed.t1.data.sum()
22
        self.assertNotEqual(total, 0)
23
24
    def test_rotation_origin(self):
25
        # Rotation around far away point, image should be empty
26
        transform = RandomAffine(
27
            degrees=(90, 90),
28
            default_pad_value=0,
29
            center='origin',
30
        )
31
        transformed = transform(self.sample)
32
        total = transformed.t1.data.sum()
33
        self.assertEqual(total, 0)
34