1
|
|
|
import torchio as tio |
2
|
|
|
from ...utils import TorchioTestCase |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
class TestEnsureShapeMultiple(TorchioTestCase): |
6
|
|
|
|
7
|
|
|
def test_bad_method(self): |
8
|
|
|
with self.assertRaises(ValueError): |
9
|
|
|
tio.EnsureShapeMultiple(1, method='bad') |
10
|
|
|
|
11
|
|
|
def test_pad(self): |
12
|
|
|
sample_t1 = self.sample_subject.t1 |
13
|
|
|
assert sample_t1.shape == (1, 10, 20, 30) |
14
|
|
|
transform = tio.EnsureShapeMultiple(4, method='pad') |
15
|
|
|
transformed = transform(sample_t1) |
16
|
|
|
assert transformed.shape == (1, 12, 20, 32) |
17
|
|
|
|
18
|
|
|
def test_crop(self): |
19
|
|
|
sample_t1 = self.sample_subject.t1 |
20
|
|
|
assert sample_t1.shape == (1, 10, 20, 30) |
21
|
|
|
transform = tio.EnsureShapeMultiple(4, method='crop') |
22
|
|
|
transformed = transform(sample_t1) |
23
|
|
|
assert transformed.shape == (1, 8, 20, 28) |
24
|
|
|
|
25
|
|
|
def test_2d(self): |
26
|
|
|
sample_t1 = self.sample_subject.t1 |
27
|
|
|
sample_2d = sample_t1.data[..., :1] |
28
|
|
|
assert sample_2d.shape == (1, 10, 20, 1) |
29
|
|
|
transform = tio.EnsureShapeMultiple(4, method='crop') |
30
|
|
|
transformed = transform(sample_2d) |
31
|
|
|
assert transformed.shape == (1, 8, 20, 1) |
32
|
|
|
|