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, )
def test_with_ghosting(self): transform = RandomGhosting() transformed = transform(self.sample_subject) self.assertTensorNotEqual( self.sample_subject.t1.data, transformed.t1.data, )
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))
def test_negative_num_ghosts(self): with self.assertRaises(ValueError): RandomGhosting(num_ghosts=-1)
def test_wrong_intensity_type(self): with self.assertRaises(ValueError): RandomGhosting(intensity='wrong')
def test_intensity_range_with_negative_min(self): with self.assertRaises(ValueError): RandomGhosting(intensity=(-0.5, 4))
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)
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)
def test_with_zero_ghost(self): transform = RandomGhosting(num_ghosts=0) transformed = transform(self.sample) self.assertTensorAlmostEqual(self.sample.t1.data, transformed.t1.data)
def test_wrong_restore_type(self): with self.assertRaises(TypeError): RandomGhosting(restore='wrong')
def test_with_zero_intensity(self): transform = RandomGhosting(intensity=0) transformed = transform(self.sample) assert_array_equal(self.sample.t1.data, transformed.t1.data)
def test_num_ghosts_range_with_negative_min(self): with self.assertRaises(ValueError): RandomGhosting(num_ghosts=(-1, 4))