def binary_blobs(length=512, blob_size_fraction=0.1, n_dim=2, volume_fraction=0.5, seed=None):
 rs = np.random.RandomState(seed)
 shape = tuple(([length] * n_dim))
 mask = np.zeros(shape)
 n_pts = max((int((1.0 / blob_size_fraction)) ** n_dim), 1)
 points = (length * rs.rand(n_dim, n_pts)).astype(np.int)
 mask[[indices for indices in points]] = 1
 mask = gaussian(mask, sigma=((0.25 * length) * blob_size_fraction))
 threshold = np.percentile(mask, (100 * (1 - volume_fraction)))
 return np.logical_not((mask < threshold))

def binary_blobs ( length = 512 , blob_size_fraction = 0.1 , n_dim = 2 , volume_fraction = 0.5 , seed = None ) : rs = np . random . RandomState ( seed ) shape = tuple ( ( [ length ] * n_dim ) ) mask = np . zeros ( shape ) n_pts = max ( ( int ( ( 1.0 / blob_size_fraction ) ) ** n_dim ) , 1 ) points = ( length * rs . rand ( n_dim , n_pts ) ) . astype ( np . int ) mask [ [ indices for indices in points ] ] = 1 mask = gaussian ( mask , sigma = ( ( 0.25 * length ) * blob_size_fraction ) ) threshold = np . percentile ( mask , ( 100 * ( 1 - volume_fraction ) ) ) return np . logical_not ( ( mask < threshold ) )
generate synthetic binary image with several rounded blob-like objects .