Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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)
Example #7
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)
Example #8
0
    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)
Example #9
0
 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/')
Example #10
0
 def test_empty_arguments_from_file(self):
     img = Image()
     self.assertRaises(TypeError, img.from_file)
Example #11
0
 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)
Example #12
0
 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))
Example #13
0
 def test_from_file_does_not_exist(self):
     img = Image()
     self.assertRaises(ValueError, img.from_file, filename='bla/image.tif')
Example #14
0
 def test_empty_arguments(self):
     img = Image()
     for var in ['image', 'filename']:
         self.assertIn(var, img.__dict__)
         self.assertEqual(img.__dict__[var], None)
Example #15
0
 def test_noise_None(self):
     img = Image()
     self.assertRaises(ValueError, img.add_noise, 'poisson', 2)
Example #16
0
 def test_convolve_None(self):
     img = Image()
     psf = PSF()
     psf.generate(sigma=5, aspect_ratio=4)
     self.assertRaises(ValueError, img.convolve, psf)
Example #17
0
 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)
Example #18
0
 def test_noise_None2(self):
     img = Image()
     self.assertRaises(ValueError, img.add_noise, 'gaussian', 2)