I have the following image (image is fully black, don't mind the border)
I want to be left only with the (1 pixel-wide) line, and be rid of all the points (some of which are actually a couple of pixels).
I know this is rather easy, but i am out of ideas for now :(
What I have tried:
a morphology operation for opening (erode + dilate) - left me with either nothing or the same
blob detection - doing this would maybe work after dilation, but it crashes with no error (windows exception), and I have no time to debug opencv.
would love any idea that works.
I ended up doing the following, just to get done with it. I am sure something smarter could have been done:
thread_defect_mask_clean = thread_defect_mask_noisy.copy()
ret, connected_components_labels = cv2.connectedComponents(thread_defect_mask_noisy.astype('uint8'), connectivity=8)
for label in range(1, ret):
label_count = np.count_nonzero(label == connected_components_labels)
if label_count < self._min_thread_defect_size:
thread_defect_mask_clean[label == connected_components_labels] = 0
This counts the size of each connected component, and enforces a threshold (5 here)