Passed
Pull Request — main (#1308)
by
unknown
02:17 queued 34s
created

TestCrop.test_subject_copy()   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 torch
2
3
import torchio as tio
4
5
from ...utils import TorchioTestCase
6
7
8
class TestCrop(TorchioTestCase):
9
    def test_tensor_single_channel(self):
10
        crop = tio.Crop(1)
11
        assert crop(torch.rand(1, 10, 10, 10)).shape == (1, 8, 8, 8)
12
13
    def test_tensor_multi_channel(self):
14
        crop = tio.Crop(1)
15
        assert crop(torch.rand(3, 10, 10, 10)).shape == (3, 8, 8, 8)
16
17
    def test_subject_copy(self):
18
        crop = tio.Crop(1, copy=True)
19
        subject = tio.Subject(t1=tio.ScalarImage(tensor=torch.rand(1, 10, 10, 10)))
20
        cropped_subject = crop(subject)
21
        assert cropped_subject.t1.shape == (1, 8, 8, 8)
22
        assert subject.t1.shape == (1, 10, 10, 10)
23
24
    def test_subject_no_copy(self):
25
        crop = tio.Crop(1, copy=False)
26
        subject = tio.Subject(t1=tio.ScalarImage(tensor=torch.rand(1, 10, 10, 10)))
27
        cropped_subject = crop(subject)
28
        assert cropped_subject.t1.shape == (1, 8, 8, 8)
29
        assert subject.t1.shape == (1, 8, 8, 8)
30