图像后处理去除比较小的连通域

版权声明:本文为博主CSDN Rosefun96原创文章。 https://blog.csdn.net/rosefun96/article/details/88864947

1. 理论

>>> from skimage import morphology
>>> a = np.array([[0, 0, 0, 1, 0],
...               [1, 1, 1, 0, 0],
...               [1, 1, 1, 0, 1]], bool)
>>> b = morphology.remove_small_objects(a, 6)
>>> b
array([[False, False, False, False, False],
       [ True,  True,  True, False, False],
       [ True,  True,  True, False, False]], dtype=bool)
>>> c = morphology.remove_small_objects(a, 7, connectivity=2)
>>> c
array([[False, False, False,  True, False],
       [ True,  True,  True, False, False],
       [ True,  True,  True, False, False]], dtype=bool)
>>> d = morphology.remove_small_objects(a, 6, in_place=True)
>>> d is a
True
from skimage import morphology
a = np.array([[0, 0, 0, 10, 0],
[10, 10, 10, 0, 0],
[10, 10, 10, 0, 10]])

b =  np.array([[0, 20, 0, 0, 0],
[20, 20, 20, 0, 0],
[0, 0, 20, 0, 0]])
c = a + b
res = morphology.remove_small_objects(c.astype(bool), 6, connectivity = 2)

参考:

  1. skimage

猜你喜欢

转载自blog.csdn.net/rosefun96/article/details/88864947