These are my code for flood filling the my image, so what i want was just the outerspace that got color value of 50, but instead everything is grayed out.
checkers = invert(cv2.imread('skeleton2.jpg',cv2.IMREAD_GRAYSCALE))
filled_checkers = flood_fill(checkers, (0, 0),50,tolerance=1)
fig, ax = plt.subplots(ncols=2, figsize=(10, 5))
ax[0].imshow(checkers, cmap=plt.cm.gray, vmin=0, vmax=255)
ax[0].set_title('Original')
ax[1].imshow(filled_checkers, cmap=plt.cm.gray, vmin=0, vmax=255)
ax[1].set_title('After flood fill')
plt.show()
What I want https://i.sstatic.net/WuQAO.jpg
What I get https://i.sstatic.net/P2pd0.jpg
You need to pass connectivity=1
as a parameter. See the documentation for flood fill:
selem: ndarray, optional
A structuring element used to determine the neighborhood of each evaluated pixel. It must contain only 1’s and 0’s, have the same number of dimensions as image. If not given, all adjacent pixels are considered as part of the neighborhood (fully connected).
connectivity: int, optional
A number used to determine the neighborhood of each evaluated pixel. Adjacent pixels whose squared distance from the center is less than or equal to connectivity are considered neighbors. Ignored if selem is not None.
The examples section in the docstring also contains examples explaining the connectivity.