I have a white and black image. I try to remove noise by 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()
However, it didn't work as I expected. The white pixel 255 in the middle is still there.
Did I do something wrong? Thanks