Passed
Push — master ( ee7d65...860ded )
by Fernando
01:26
created

tests.transforms.preprocessing.test_resize   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 26
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestResize.test_one_dim() 0 6 2
A TestResize.test_fix_shape() 0 9 2
A TestResize.test_all_dims() 0 6 2
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