|
1
|
|
|
from torchio import RandomGhosting |
|
2
|
|
|
from ...utils import TorchioTestCase |
|
3
|
|
|
from numpy.testing import assert_array_equal |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class TestRandomGhosting(TorchioTestCase): |
|
7
|
|
|
"""Tests for `RandomGhosting`.""" |
|
8
|
|
|
def test_with_zero_intensity(self): |
|
9
|
|
|
transform = RandomGhosting(intensity=0) |
|
10
|
|
|
transformed = transform(self.sample) |
|
11
|
|
|
assert_array_equal(self.sample.t1.data, transformed.t1.data) |
|
12
|
|
|
|
|
13
|
|
|
def test_with_zero_ghost(self): |
|
14
|
|
|
transform = RandomGhosting(num_ghosts=0) |
|
15
|
|
|
transformed = transform(self.sample) |
|
16
|
|
|
assert_array_equal(self.sample.t1.data, transformed.t1.data) |
|
17
|
|
|
|
|
18
|
|
|
def test_with_ghosting(self): |
|
19
|
|
|
transform = RandomGhosting() |
|
20
|
|
|
transformed = transform(self.sample) |
|
21
|
|
|
with self.assertRaises(AssertionError): |
|
22
|
|
|
assert_array_equal(self.sample.t1.data, transformed.t1.data) |
|
23
|
|
|
|
|
24
|
|
|
def test_intensity_range_with_negative_min(self): |
|
25
|
|
|
with self.assertRaises(ValueError): |
|
26
|
|
|
RandomGhosting(intensity=(-0.5, 4)) |
|
27
|
|
|
|
|
28
|
|
|
def test_wrong_intensity_type(self): |
|
29
|
|
|
with self.assertRaises(ValueError): |
|
30
|
|
|
RandomGhosting(intensity='wrong') |
|
31
|
|
|
|
|
32
|
|
|
def test_negative_num_ghosts(self): |
|
33
|
|
|
with self.assertRaises(ValueError): |
|
34
|
|
|
RandomGhosting(num_ghosts=-1) |
|
35
|
|
|
|
|
36
|
|
|
def test_num_ghosts_range_with_negative_min(self): |
|
37
|
|
|
with self.assertRaises(ValueError): |
|
38
|
|
|
RandomGhosting(num_ghosts=(-1, 4)) |
|
39
|
|
|
|
|
40
|
|
|
def test_not_integer_num_ghosts(self): |
|
41
|
|
|
with self.assertRaises(ValueError): |
|
42
|
|
|
RandomGhosting(num_ghosts=(0.7, 4)) |
|
43
|
|
|
|
|
44
|
|
|
def test_wrong_num_ghosts_type(self): |
|
45
|
|
|
with self.assertRaises(ValueError): |
|
46
|
|
|
RandomGhosting(num_ghosts='wrong') |
|
47
|
|
|
|
|
48
|
|
|
def test_out_of_range_axis(self): |
|
49
|
|
|
with self.assertRaises(ValueError): |
|
50
|
|
|
RandomGhosting(axes=3) |
|
51
|
|
|
|
|
52
|
|
|
def test_out_of_range_axis_in_tuple(self): |
|
53
|
|
|
with self.assertRaises(ValueError): |
|
54
|
|
|
RandomGhosting(axes=(0, -1, 2)) |
|
55
|
|
|
|
|
56
|
|
|
def test_wrong_axes_type(self): |
|
57
|
|
|
with self.assertRaises(ValueError): |
|
58
|
|
|
RandomGhosting(axes='wrong') |
|
59
|
|
|
|
|
60
|
|
|
def test_out_of_range_restore(self): |
|
61
|
|
|
with self.assertRaises(ValueError): |
|
62
|
|
|
RandomGhosting(restore=-1.) |
|
63
|
|
|
|
|
64
|
|
|
def test_wrong_restore_type(self): |
|
65
|
|
|
with self.assertRaises(TypeError): |
|
66
|
|
|
RandomGhosting(restore='wrong') |
|
67
|
|
|
|