Last active
September 11, 2017 18:39
-
-
Save creotiv/cd0ca7ed33739ac690f5e71ee9383799 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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