将图像背景设置为0 - Skimage

时间:2018-02-18 19:53:44

标签: python mask scikit-image

我正在使用Skimage v0.14

我想做这段代码的反转

image[leaf_cleaned] = 0

这里我将屏蔽区域设置为0,我实际想要的是除了屏蔽区域为0或任何数字之外的所有内容。

这是我的其余代码:

image = imread('')

grey_image = rgb2grey(image)
entireLeaf = feature.canny(grey_image) 

blurred = filters.gaussian(entireLeaf, sigma=0.4)  


fillleaf = ndi.binary_fill_holes(blurred) 

label_objects, nb_labels = ndi.label(fillleaf) 
sizes = np.bincount(label_objects.ravel()) 
mask_sizes = sizes > 100000             
mask_sizes[0] = 0
leaf_cleaned = mask_sizes[label_objects]

1 个答案:

答案 0 :(得分:1)

如果leaf_cleaned是布尔数组like used for masks,您可以这样做:

image[~leaf_cleaned] = 0

紧跟numpy的boolean-indexing docs

请记住,sklearn严重依赖于numpy!所以numpy的文档经常是相关的!