我有一个黑白图像。我尝试消除噪音remove_small_objects
。
import cv2 as cv
import numpy as np
from skimage import morphology
img = np.array([[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 0, 255, 0, 0, 0, 0, 255, 255, 255],
[255, 255, 255, 255, 0, 0, 0, 0, 255, 0, 0],
[255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[255, 255, 0, 0, 0, 0, 0, 255, 0, 0, 0],
[255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0],
[255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
cleaned = morphology.remove_small_objects(img, min_size=10, connectivity=1)
print(cleaned)
while True:
cv.imshow('Demo', cleaned.astype(np.uint8))
if cv.waitKey(1) & 0xFF == 27:
break
cv.destroyAllWindows()
然而,它并没有像我预期的那样工作。中间的白色像素 255 仍然存在。
我做错什么了吗?谢谢