Esempio 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,
     )
Esempio 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,
     )
Esempio 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)
 def test_out_of_range_restore(self):
     with self.assertRaises(ValueError):
         RandomGhosting(restore=-1.)
 def test_wrong_axes_type(self):
     with self.assertRaises(ValueError):
         RandomGhosting(axes=None)
 def test_out_of_range_axis_in_tuple(self):
     with self.assertRaises(ValueError):
         RandomGhosting(axes=(0, -1, 2))
 def test_out_of_range_axis(self):
     with self.assertRaises(ValueError):
         RandomGhosting(axes=3)
 def test_wrong_num_ghosts_type(self):
     with self.assertRaises(ValueError):
         RandomGhosting(num_ghosts='wrong')
 def test_not_integer_num_ghosts(self):
     with self.assertRaises(ValueError):
         RandomGhosting(num_ghosts=(0.7, 4))
Esempio n. 10
0
 def test_negative_num_ghosts(self):
     with self.assertRaises(ValueError):
         RandomGhosting(num_ghosts=-1)
Esempio n. 11
0
 def test_wrong_intensity_type(self):
     with self.assertRaises(ValueError):
         RandomGhosting(intensity='wrong')
Esempio n. 12
0
 def test_intensity_range_with_negative_min(self):
     with self.assertRaises(ValueError):
         RandomGhosting(intensity=(-0.5, 4))
Esempio 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)
Esempio 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)
Esempio 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)
Esempio n. 16
0
 def test_wrong_restore_type(self):
     with self.assertRaises(TypeError):
         RandomGhosting(restore='wrong')
Esempio 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)
Esempio n. 18
0
 def test_num_ghosts_range_with_negative_min(self):
     with self.assertRaises(ValueError):
         RandomGhosting(num_ghosts=(-1, 4))