Skip to content

Instantly share code, notes, and snippets.

@creotiv
Last active September 11, 2017 18:39
Show Gist options
  • Select an option

  • Save creotiv/cd0ca7ed33739ac690f5e71ee9383799 to your computer and use it in GitHub Desktop.

Select an option

Save creotiv/cd0ca7ed33739ac690f5e71ee9383799 to your computer and use it in GitHub Desktop.
def filter_mask(img):
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2))
# Fill any small holes
closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)
# Remove noise
opening = cv2.morphologyEx(closing, cv2.MORPH_OPEN, kernel)
# Dilate to merge adjacent blobs
dilation = cv2.dilate(opening, kernel, iterations=2)
# threshold
th = dilation[dilation < 240] = 0
return th
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment