def get_largest_component(self, closing_shape=None):
mask, bounds = self._get_bounded_mask(closing_shape)
label_im, num_labels = ndimage.label(mask)
label_sizes = ndimage.sum(mask, label_im, range(num_labels + 1))
label_im[(label_sizes < label_sizes.max())[label_im]] = 0
label_im = np.minimum(label_im, 1)
if label_im[tuple(self.seed - bounds[0])] == 0:
logging.warning('Seed voxel ({}) is not in connected component.'.format(np.array_str(self.seed)))
return label_im, bounds
评论列表
文章目录