Esempio n. 1
0
 def __init__(self, shape, size, dtype=np.uint8, saturation=None,
              hard_radius=None, signal=None, noise=0,
              feat_func=feat_gauss, **feat_kwargs):
     self.ndim = len(shape)
     self.shape = shape
     self.dtype = dtype
     self.image = np.zeros(shape, dtype=dtype)
     if _Frame is not None:
         self.image = _Frame(self.image)
     self.size = validate_tuple(size, self.ndim)
     self.isotropic = np.all([self.size[1:] == self.size[:-1]])
     self.feat_func = feat_func
     self.feat_kwargs = feat_kwargs
     self.noise = noise
     if saturation is None and np.issubdtype(dtype, np.integer):
         self.saturation = np.iinfo(dtype).max
     elif saturation is None and np.issubdtype(dtype, np.floating):
         self.saturation = 1
     else:
         self.saturation = saturation
     if signal is None:
         self.signal = self.saturation
     else:
         self.signal = signal
     self.center = tuple([s // 2 for s in shape])
     self.hard_radius = hard_radius
     self._coords = []
     self.pos_columns = ['z', 'y', 'x'][-self.ndim:]
     if self.isotropic:
         self.size_columns = ['size']
     else:
         self.size_columns = ['size_z', 'size_y', 'size_x'][-self.ndim:]
Esempio n. 2
0
 def noisy_image(self, noise_level):
     """Adds noise to the current image, uniformly distributed
     between 0 and `noise_level`, not including noise_level."""
     if noise_level <= 0:
         return self.image
     if np.issubdtype(self.dtype, np.integer):
         noise = np.random.poisson(noise_level, self.shape)
     else:
         noise = np.clip(np.random.normal(noise_level, noise_level/2, self.shape), 0, self.saturation)
     noisy_image = np.clip(self.image + noise, 0, self.saturation)
     result = np.array(noisy_image, dtype=self.dtype)
     if _Frame is not None:
         result = _Frame(result)
     return result
Esempio n. 3
0
 def noisy_image(self, noise_level):
     """Adds noise to the current image, uniformly distributed
     between 0 and `noise_level`, not including noise_level."""
     if noise_level <= 0:
         return self.image
     if np.issubdtype(self.dtype, np.integer):
         noise = np.random.poisson(noise_level, self.shape)
     else:
         noise = np.clip(
             np.random.normal(noise_level, noise_level / 2, self.shape), 0,
             self.saturation)
     noisy_image = np.clip(self.image + noise, 0, self.saturation)
     result = np.array(noisy_image, dtype=self.dtype)
     if _Frame is not None:
         result = _Frame(result)
     return result
Esempio n. 4
0
 def __init__(self,
              shape,
              size,
              dtype=np.uint8,
              saturation=None,
              hard_radius=None,
              signal=None,
              noise=0,
              feat_func=feat_gauss,
              **feat_kwargs):
     self.ndim = len(shape)
     self.shape = shape
     self.dtype = dtype
     self.image = np.zeros(shape, dtype=dtype)
     if _Frame is not None:
         self.image = _Frame(self.image)
     self.size = validate_tuple(size, self.ndim)
     self.isotropic = np.all([self.size[1:] == self.size[:-1]])
     self.feat_func = feat_func
     self.feat_kwargs = feat_kwargs
     self.noise = noise
     if saturation is None and np.issubdtype(dtype, np.integer):
         self.saturation = np.iinfo(dtype).max
     elif saturation is None and np.issubdtype(dtype, np.floating):
         self.saturation = 1
     else:
         self.saturation = saturation
     if signal is None:
         self.signal = self.saturation
     else:
         self.signal = signal
     self.center = tuple([s // 2 for s in shape])
     self.hard_radius = hard_radius
     self._coords = []
     self.pos_columns = ['z', 'y', 'x'][-self.ndim:]
     if self.isotropic:
         self.size_columns = ['size']
     else:
         self.size_columns = ['size_z', 'size_y', 'size_x'][-self.ndim:]