|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
|
|
3
|
|
|
"""Tests for Image.""" |
|
4
|
|
|
|
|
5
|
|
|
import torch |
|
6
|
|
|
from torchio import INTENSITY, Image |
|
7
|
|
|
from ..utils import TorchioTestCase |
|
8
|
|
|
from torchio import RandomFlip, RandomAffine |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class TestImage(TorchioTestCase): |
|
12
|
|
|
"""Tests for `Image`.""" |
|
13
|
|
|
|
|
14
|
|
|
def test_image_not_found(self): |
|
15
|
|
|
with self.assertRaises(FileNotFoundError): |
|
16
|
|
|
Image('nopath', type=INTENSITY) |
|
17
|
|
|
|
|
18
|
|
|
def test_wrong_path_type(self): |
|
19
|
|
|
with self.assertRaises(TypeError): |
|
20
|
|
|
Image(5, type=INTENSITY) |
|
21
|
|
|
|
|
22
|
|
|
def test_wrong_affine(self): |
|
23
|
|
|
with self.assertRaises(TypeError): |
|
24
|
|
|
Image(5, type=INTENSITY, affine=1) |
|
25
|
|
|
|
|
26
|
|
|
def test_tensor_flip(self): |
|
27
|
|
|
sample_input = torch.ones((4, 30, 30, 30)) |
|
28
|
|
|
RandomFlip()(sample_input) |
|
29
|
|
|
|
|
30
|
|
|
def test_tensor_affine(self): |
|
31
|
|
|
sample_input = torch.ones((4, 10, 10, 10)) |
|
32
|
|
|
RandomAffine()(sample_input) |
|
33
|
|
|
|
|
34
|
|
|
def test_crop_attributes(self): |
|
35
|
|
|
cropped = self.sample.crop((1, 1, 1), (5, 5, 5)) |
|
36
|
|
|
self.assertIs(self.sample.t1['pre_affine'], cropped.t1['pre_affine']) |
|
37
|
|
|
|