Reputation: 23
I have binary images, and I would like to know if a given dark (0) pixel is inside a closed region (the pixel is surrounded by a closed line of bright pixels) or open region (there is a path of dark pixels from this target pixel to the boundary).
For instance, in the image the pixel at (200,200) is inside a closed region. In the other image
, the pixel at (200,200) is in an open region.
I used the watershed algorithm of scipy with markers on the target pixel and a boundary dark pixel, which runs in ~10ms (order of magnitude). But I have to repeat this process multiple time in my project, and I wanted to know if there are faster algorithms to do this, or other methods to adress the problem.
I am using Python, so I thought about coding a "truncated" watershed by just exploring the neighbours of the target pixel and see if we can reach the boundary but I doubt it will be faster.
EDIT
I modified the images so that you can load them as png. I work with the binary image:
img = cv.imread('closed_region.png')
img = cv.cvtColor(img, cv.COLOR_RGB2GRAY) # color to gray
_, img = cv.threshold(img,10,1,0) # binary img
and I currently use the following to see if a target pixel (200,200) is in an open (same as (0,0) here) or closed region.
from scipy.ndimage import watershed_ift
markers = np.zeros(img.shape, dtype=np.int8)
markers[200,200] = 2
markers[0,0] = 1
water = watershed_ift(img, markers)
Upvotes: 0
Views: 44
Reputation: 23
I found the answer to the problem: opencv "cv.floodFill" function does exactly what I want, and is muche faster than scipy watershed (by a factor of ~100).
Upvotes: 1