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

TestResize.test_all_dims()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nop 1
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