Home > Back-end >  How to fill the gap created after thresholding the image?
How to fill the gap created after thresholding the image?

Time:12-14

I'm trying to segment the hand out of the image using OpenCV python. One of the images contains a ring on one of the fingers as shown here

1

After thresholding I get this result:

2

How can I reconnect the finger after thresholding?

CodePudding user response:

Don't know how you thresholded your image, but if we use it and morphological closing we can close some gaps:

morph = cv2.morphologyEx(threshold_img, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (31, 31)))

Symmetrical closing

One problem you can notice is it closes in all directions. If you know there are more likely gaps in vertical direction you can change the structuring element accordingly:

morph = cv2.morphologyEx(threshold_img, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (11, 31)))

Asymmetrical closing

  • Related