在scikit-image中去除标签

1 投票
1 回答
3827 浏览
提问于 2025-04-18 06:07

我有一张二值图像,已经给它标记了不同的区域。

enter image description here
imageLabels = morphology.label(imageBinary, background=255)

但是当我检查标记的数量时,发现有535个元素。

print(len(imageLabels))

为了解决这个问题,我想到了使用 measure.regionprops 来去掉那些像素面积很小的标记。你们会怎么做呢?我尝试了以下方法,但由于某种原因,新的数组不再被视为有效的标记元素。

i=0
for labelprop in measure.regionprops(imageLabels):
    if (labelprop.area > 100):
        imageLabels_keep.append(imageLabels[i])
    i=i+1

1 个回答

4

我觉得 morphology.remove_small_objects(image, min_px_size) 这个函数正是你需要的。下面是一个使用这个函数的例子:

http://scikit-image.org/docs/dev/auto_examples/applications/plot_coins_segmentation.html#edge-based-segmentation

撰写回答