Passed
Pull Request — master (#334)
by Fernando
01:13
created

tests.transforms.preprocessing.test_pad   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A TestPad.test_pad() 0 11 1
1
import torch
2
import SimpleITK as sitk
3
from torchio.utils import sitk_to_nib
4
from torchio.transforms import Pad
5
from ...utils import TorchioTestCase
6
7
8
class TestPad(TorchioTestCase):
9
    """Tests for `Pad`."""
10
    def test_pad(self):
11
        image = self.sample.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 = 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