def test_invalid_noise_types2(self, case): kind, snr = case img = Image() arr = np.zeros([50, 50, 50]) arr[10:-10, 10:-10, 10:-10] = 255 img.image = arr self.assertRaises(TypeError, img.add_noise, kind=kind, snr=snr)
def test_noise2(self): img = Image() arr = np.zeros([50, 50, 50]) arr[10:-10, 10:-10, 10:-10] = 255 img.image = arr img.add_noise(kind='poisson', snr=2) self.assertEqual(img.image.shape, arr.shape)
def test_resize_larger_than_3(self, case): old_shape, zoom = case img = Image() img.image = np.ones(old_shape) img.resize(zoom=zoom) for i in range(len(img.image.shape)): self.assertGreater(img.image.shape[i], 3)
def test_voxel_size_change(self, case): old, zoom, new = case img = Image() img.image = np.ones([100, 100, 100]) img.metadata.set_voxel_size(old) img.resize(zoom=zoom) self.assertEqual(img.metadata['Voxel size'], new)
def test_valid_noise_metadata(self, case): kind, snr = case img = Image() arr = np.zeros([50, 50, 50]) arr[10:-10, 10:-10, 10:-10] = 255 img.image = arr img.add_noise(kind=kind, snr=snr) self.assertEqual(img.metadata['SNR'], snr)
def test_valid_noise_types(self, kind): img = Image() arr = np.zeros([50, 50, 50]) arr[10:-10, 10:-10, 10:-10] = 255 img.image = arr img.add_noise(kind=kind, snr=10) self.assertIsNotNone(img.image) self.assertGreater(np.sum(np.abs(img.image - arr)), 0)
def test_convolve(self): img = Image() arr = np.zeros([50, 50, 50]) arr[10:-10, 10:-10, 10:-10] = 255 img.image = arr psf = PSF() psf.generate(sigma=5, aspect_ratio=4) img.convolve(psf) self.assertEqual(len(img.image.shape), len(arr.shape)) self.assertEqual(img.metadata['Convolved'], True)
def test_filename(self, filename): img = Image(filename) for var in ['image', 'metadata', 'filename']: self.assertIn(var, img.__dict__) self.assertEqual(img.__dict__['image'], None) self.assertEqual(img.metadata['Convolved'], False) self.assertEqual(img.filename, filename)
def test_save_and_read(self, filename): img = Image() img.image = np.ones([5, 5, 5]) img.save(filename) fn = img.filename img.from_file(fn) self.assertIsNotNone(img.image) shutil.rmtree('data/')
def test_empty_arguments_from_file(self): img = Image() self.assertRaises(TypeError, img.from_file)
def test_convolve_None2(self): img = Image() arr = np.zeros([50, 50, 50]) arr[10:-10, 10:-10, 10:-10] = 255 psf = PSF() self.assertRaises(ValueError, img.convolve, psf)
def test_resize(self, case): old_shape, zoom, new_shape = case img = Image() img.image = np.ones(old_shape) img.resize(zoom=zoom) self.assertEqual(img.image.shape, tuple(new_shape))
def test_from_file_does_not_exist(self): img = Image() self.assertRaises(ValueError, img.from_file, filename='bla/image.tif')
def test_empty_arguments(self): img = Image() for var in ['image', 'filename']: self.assertIn(var, img.__dict__) self.assertEqual(img.__dict__[var], None)
def test_noise_None(self): img = Image() self.assertRaises(ValueError, img.add_noise, 'poisson', 2)
def test_convolve_None(self): img = Image() psf = PSF() psf.generate(sigma=5, aspect_ratio=4) self.assertRaises(ValueError, img.convolve, psf)
def test_invalid_noise_types(self, kind): img = Image() arr = np.zeros([50, 50, 50]) arr[10:-10, 10:-10, 10:-10] = 255 img.image = arr self.assertRaises(AttributeError, img.add_noise, kind=kind, snr=10)
def test_noise_None2(self): img = Image() self.assertRaises(ValueError, img.add_noise, 'gaussian', 2)