Completed
Pull Request — master (#401)
by Fernando
20:26 queued 20:26
created

TestEnsureShapeMultiple.test_crop()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
import torchio as tio
2
from ...utils import TorchioTestCase
3
4
5
class TestEnsureShapeMultiple(TorchioTestCase):
6
7
    def test_bad_method(self):
8
        with self.assertRaises(ValueError):
9
            tio.EnsureShapeMultiple(1, method='bad')
10
11
    def test_pad(self):
12
        sample_t1 = self.sample_subject.t1
13
        assert sample_t1.shape == (1, 10, 20, 30)
14
        transform = tio.EnsureShapeMultiple(4, method='pad')
15
        transformed = transform(sample_t1)
16
        assert transformed.shape == (1, 12, 20, 32)
17
18
    def test_crop(self):
19
        sample_t1 = self.sample_subject.t1
20
        assert sample_t1.shape == (1, 10, 20, 30)
21
        transform = tio.EnsureShapeMultiple(4, method='crop')
22
        transformed = transform(sample_t1)
23
        assert transformed.shape == (1, 8, 20, 28)
24
25
    def test_2d(self):
26
        sample_t1 = self.sample_subject.t1
27
        sample_2d = sample_t1.data[..., :1]
28
        assert sample_2d.shape == (1, 10, 20, 1)
29
        transform = tio.EnsureShapeMultiple(4, method='crop')
30
        transformed = transform(sample_2d)
31
        assert transformed.shape == (1, 8, 20, 1)
32