skimage flood_fill 填充整个图像
skimage flood_fill fill the whole images
这些是我的代码,用于填充我的图像,所以我想要的只是颜色值为 50 的外层空间,但一切都变灰了。
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()
我想要什么https://i.stack.imgur.com/WuQAO.jpg
我得到了什么https://i.stack.imgur.com/P2pd0.jpg
您需要将 connectivity=1
作为参数传递。见 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.
文档字符串中的示例部分还包含解释连接性的示例。
这些是我的代码,用于填充我的图像,所以我想要的只是颜色值为 50 的外层空间,但一切都变灰了。
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()
我想要什么https://i.stack.imgur.com/WuQAO.jpg
我得到了什么https://i.stack.imgur.com/P2pd0.jpg
您需要将 connectivity=1
作为参数传递。见 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.
文档字符串中的示例部分还包含解释连接性的示例。