Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def binary_objects(binary: np.array) -> np.array:
"""
Labels features in an array and segments them into objects.
"""
labels, _ = morph.label(binary)
objects = morph.find_objects(labels)
return objects
def compute_lines(segmentation, scale):
"""Given a line segmentation map, computes a list
of tuples consisting of 2D slices and masked images."""
logger.debug('Convert segmentation to lines')
lobjects = morph.find_objects(segmentation)
lines = []
for i, o in enumerate(lobjects):
if o is None:
continue
if sl.dim1(o) < 2*scale or sl.dim0(o) < scale:
continue
mask = (segmentation[o] == i+1)
if np.amax(mask) == 0:
continue
result = record()
result.label = i+1
result.bounds = o
result.mask = mask
lines.append(result)
return lines