Пример #1
0
 def test_no_noise(self):
     transform = RandomNoise(mean=0, std=0)
     transformed = transform(self.sample_subject)
     self.assertTensorAlmostEqual(
         self.sample_subject.t1.data,
         transformed.t1.data,
     )
Пример #2
0
 def test_with_noise(self):
     transform = RandomNoise()
     transformed = transform(self.sample_subject)
     self.assertTensorNotEqual(
         self.sample_subject.t1.data,
         transformed.t1.data,
     )
Пример #3
0
 def test_constant_noise(self):
     transform = RandomNoise(mean=(5., 5.), std=0.)
     transformed = transform(self.sample)
     self.assertTensorAlmostEqual(
         self.sample.t1.data + 5,
         transformed.t1.data,
     )
Пример #4
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)
Пример #5
0
 def test_no_noise(self):
     transform = RandomNoise(mean=0., std=0.)
     transformed = transform(self.sample)
     assert_array_equal(self.sample.t1.data, transformed.t1.data)
Пример #6
0
 def test_wrong_mean_type(self):
     with self.assertRaises(ValueError):
         RandomNoise(mean='wrong')
Пример #7
0
 def test_wrong_std_type(self):
     with self.assertRaises(ValueError):
         RandomNoise(std='wrong')
Пример #8
0
 def test_std_range_with_negative_min(self):
     with self.assertRaises(ValueError):
         RandomNoise(std=(-0.5, 4))
Пример #9
0
 def test_negative_std(self):
     with self.assertRaises(ValueError):
         RandomNoise(std=-2)
Пример #10
0
 def test_constant_noise(self):
     transform = RandomNoise(mean=(5., 5.), std=0.)
     transformed = transform(self.sample)
     assert_array_equal(self.sample.t1.data + 5, transformed.t1.data)
Пример #11
0
 def test_with_noise(self):
     transform = RandomNoise()
     transformed = transform(self.sample)
     with self.assertRaises(AssertionError):
         assert_array_equal(self.sample.t1.data, transformed.t1.data)
Пример #12
0
 def test_no_noise(self):
     transform = RandomNoise(mean=0., std=0.)
     transformed = transform(self.sample)
     self.assertTensorAlmostEqual(self.sample.t1.data, transformed.t1.data)