Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def open_by_reconstruction(src, iterations = 1, ksize = 3):
- # first erode the source image
- eroded = cv2.erode(src, np.ones((ksize,ksize), np.uint8), iterations=iterations)
- # Now we are going to iteratively regrow the eroded mask.
- # The key difference between just a simple opening is that we
- # mask the regrown everytime with the original src.
- # Thus, the dilated mask never extends beyond where it does in the original.
- this_iteration = eroded
- last_iteration = eroded
- while (True):
- this_iteration = cv2.dilate(last_iteration, np.ones((ksize,ksize), np.uint8), iterations = 1)
- this_iteration = this_iteration & src
- if np.array_equal(last_iteration, this_iteration):
- # convergence!
- break
- last_iteration = this_iteration.copy()
- return this_iteration
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement