Passed
Push — master ( 1c5439...729305 )
by Fernando
01:12
created

tests.transforms.preprocessing.test_pad   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TestPad.test_pad() 0 11 1
A TestPad.test_nans_history() 0 4 1
1
import torch
2
import SimpleITK as sitk
3
import torchio as tio
4
from torchio.utils import sitk_to_nib
5
from ...utils import TorchioTestCase
6
7
8
class TestPad(TorchioTestCase):
9
    """Tests for `Pad`."""
10
    def test_pad(self):
11
        image = self.sample_subject.t1
12
        padding = 1, 2, 3, 4, 5, 6
13
        sitk_image = image.as_sitk()
14
        low, high = padding[::2], padding[1::2]
15
        sitk_padded = sitk.ConstantPad(sitk_image, low, high, 0)
16
        tio_padded = tio.Pad(padding, padding_mode=0)(image)
17
        sitk_tensor, sitk_affine = sitk_to_nib(sitk_padded)
18
        tio_tensor, tio_affine = sitk_to_nib(tio_padded.as_sitk())
19
        self.assertTensorEqual(sitk_tensor, tio_tensor)
20
        self.assertTensorEqual(sitk_affine, tio_affine)
21
22
    def test_nans_history(self):
23
        padded = tio.Pad(1, padding_mode=2)(self.sample_subject)
24
        again = padded.history[0](self.sample_subject)
25
        assert not torch.isnan(again.t1.data).any()
26