Exemplo n.º 1
0
 def test_with_zero_intensity(self):
     transform = RandomGhosting(intensity=0)
     transformed = transform(self.sample_subject)
     self.assertTensorAlmostEqual(
         self.sample_subject.t1.data,
         transformed.t1.data,
     )
Exemplo n.º 2
0
 def test_with_ghosting(self):
     transform = RandomGhosting()
     transformed = transform(self.sample_subject)
     self.assertTensorNotEqual(
         self.sample_subject.t1.data,
         transformed.t1.data,
     )
Exemplo n.º 3
0
def simulate_artefacts(sample, artefacts=(0, 0, 0, 0)):
    transforms = []
    if artefacts[0] == 1:
        if random.random() < 0.5:
            degrees = (5, random.random() * 10 + 5)
        else:
            degrees = (-(random.random() * 10 + 5), -5)
        if random.random() < 0.5:
            translation = (5, random.random() * 10 + 5)
        else:
            translation = (-(random.random() * 10 + 5), -5)
        transforms.append(
            RandomMotion(degrees=degrees,
                         translation=translation,
                         num_transforms=random.randint(2, 15)))
    elif artefacts[1] == 1:
        transforms.append(
            RandomGhosting(num_ghosts=(2, 10), intensity=(0.5, 0.75)))
    elif artefacts[2] == 1:
        transforms.append(RandomBlur(std=(0.5, 2.)))
    elif artefacts[3] == 1:
        transforms.append(RandomNoise(std=(0.01, 0.05)))
    transforms = Compose(transforms)
    return transforms(sample)
Exemplo n.º 4
0
 def test_out_of_range_restore(self):
     with self.assertRaises(ValueError):
         RandomGhosting(restore=-1.)
Exemplo n.º 5
0
 def test_wrong_axes_type(self):
     with self.assertRaises(ValueError):
         RandomGhosting(axes=None)
Exemplo n.º 6
0
 def test_out_of_range_axis_in_tuple(self):
     with self.assertRaises(ValueError):
         RandomGhosting(axes=(0, -1, 2))
Exemplo n.º 7
0
 def test_out_of_range_axis(self):
     with self.assertRaises(ValueError):
         RandomGhosting(axes=3)
Exemplo n.º 8
0
 def test_wrong_num_ghosts_type(self):
     with self.assertRaises(ValueError):
         RandomGhosting(num_ghosts='wrong')
Exemplo n.º 9
0
 def test_not_integer_num_ghosts(self):
     with self.assertRaises(ValueError):
         RandomGhosting(num_ghosts=(0.7, 4))
Exemplo n.º 10
0
 def test_negative_num_ghosts(self):
     with self.assertRaises(ValueError):
         RandomGhosting(num_ghosts=-1)
Exemplo n.º 11
0
 def test_wrong_intensity_type(self):
     with self.assertRaises(ValueError):
         RandomGhosting(intensity='wrong')
Exemplo n.º 12
0
 def test_intensity_range_with_negative_min(self):
     with self.assertRaises(ValueError):
         RandomGhosting(intensity=(-0.5, 4))
Exemplo n.º 13
0
 def test_with_ghosting(self):
     transform = RandomGhosting()
     transformed = transform(self.sample)
     with self.assertRaises(AssertionError):
         assert_array_equal(self.sample.t1.data, transformed.t1.data)
Exemplo n.º 14
0
 def test_with_zero_ghost(self):
     transform = RandomGhosting(num_ghosts=0)
     transformed = transform(self.sample)
     assert_array_equal(self.sample.t1.data, transformed.t1.data)
Exemplo n.º 15
0
 def test_with_zero_ghost(self):
     transform = RandomGhosting(num_ghosts=0)
     transformed = transform(self.sample)
     self.assertTensorAlmostEqual(self.sample.t1.data, transformed.t1.data)
Exemplo n.º 16
0
 def test_wrong_restore_type(self):
     with self.assertRaises(TypeError):
         RandomGhosting(restore='wrong')
Exemplo n.º 17
0
 def test_with_zero_intensity(self):
     transform = RandomGhosting(intensity=0)
     transformed = transform(self.sample)
     assert_array_equal(self.sample.t1.data, transformed.t1.data)
Exemplo n.º 18
0
 def test_num_ghosts_range_with_negative_min(self):
     with self.assertRaises(ValueError):
         RandomGhosting(num_ghosts=(-1, 4))