Home > Software design >  How can I remove black dots around hand in image
How can I remove black dots around hand in image

Time:07-26

using opencv for capturing image in python

i want to make this image :

code for this :

# Image Processing
gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (51,51), 15) 
th3 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
ret, test_image = cv2.threshold(th3, 10, 255, cv2.THRESH_BINARY_INV cv2.THRESH_OTSU)

enter image description here

to somewhat like this:

enter image description here

CodePudding user response:

If you'll consider Original image and two post-processes versions

CodePudding user response:

I think you should try closing operation. It will do the work.

gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (51,51), 15) 
th3 = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)
ret, test_image = cv2.threshold(th3, 10, 255, cv2.THRESH_BINARY_INV cv2.THRESH_OTSU)

kernel = np.ones((3, 3), np.uint8)

# opening the image
opening = cv2.morphologyEx(binr, cv2.MORPH_OPEN,
                           kernel, iterations=1)

If the resultant image is not good enough then try to increase he kernal size

  • Related