def test_parse_stds(self):
        def do_assert(transform):
            self.assertEqual(transform.std_ranges, 3 * (0, 1))

        do_assert(RandomBlur(std=1))
        do_assert(RandomBlur(std=(0, 1)))
        do_assert(RandomBlur(std=3 * (1, )))
        do_assert(RandomBlur(std=3 * [0, 1]))
 def test_no_blurring(self):
     transform = RandomBlur(std=0)
     transformed = transform(self.sample_subject)
     self.assertTensorAlmostEqual(
         self.sample_subject.t1.data,
         transformed.t1.data,
     )
 def test_with_blurring(self):
     transform = RandomBlur(std=(1, 3))
     transformed = transform(self.sample_subject)
     self.assertTensorNotEqual(
         self.sample_subject.t1.data,
         transformed.t1.data,
     )
Exemple #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)
Exemple #5
0
 def test_no_blurring(self):
     transform = RandomBlur(std=0)
     transformed = transform(self.sample)
     assert_array_equal(self.sample.t1.data, transformed.t1.data)
Exemple #6
0
 def test_wrong_std_type(self):
     with self.assertRaises(ValueError):
         RandomBlur(std='wrong')
Exemple #7
0
 def test_std_range_with_negative_min(self):
     with self.assertRaises(ValueError):
         RandomBlur(std=(-0.5, 4))
Exemple #8
0
 def test_negative_std(self):
     with self.assertRaises(ValueError):
         RandomBlur(std=-2)
Exemple #9
0
 def test_with_blurring(self):
     transform = RandomBlur(std=(1, 3))
     transformed = transform(self.sample)
     with self.assertRaises(AssertionError):
         assert_array_equal(self.sample.t1.data, transformed.t1.data)