def get_masks(img, n_seg=250):
logger.debug('SLIC segmentation initialised')
segments = skimage.segmentation.slic(img, n_segments=n_seg, compactness=10, sigma=1)
logger.debug('SLIC segmentation complete')
logger.debug('contour extraction...')
masks = [[numpy.zeros((img.shape[0], img.shape[1]), dtype=numpy.uint8), None]]
for region in skimage.measure.regionprops(segments):
masks.append([masks[0][0].copy(), region.bbox])
x_min, y_min, x_max, y_max = region.bbox
masks[-1][0][x_min:x_max, y_min:y_max] = skimage.img_as_ubyte(region.convex_image)
logger.debug('contours extracted')
return masks[1:]
评论列表
文章目录