备注
单击 here 下载完整的示例代码或通过活页夹在浏览器中运行此示例
凸壳¶
二值图像的凸包是包含在围绕输入中所有白色像素的最小凸多边形中的一组像素。
上对该算法进行了很好的概述 Steve Eddin's blog 。
import matplotlib.pyplot as plt
from skimage.morphology import convex_hull_image
from skimage import data, img_as_float
from skimage.util import invert
# The original image is inverted as the object must be white.
image = invert(data.horse())
chull = convex_hull_image(image)
fig, axes = plt.subplots(1, 2, figsize=(8, 4))
ax = axes.ravel()
ax[0].set_title('Original picture')
ax[0].imshow(image, cmap=plt.cm.gray)
ax[0].set_axis_off()
ax[1].set_title('Transformed picture')
ax[1].imshow(chull, cmap=plt.cm.gray)
ax[1].set_axis_off()
plt.tight_layout()
plt.show()

我们准备了第二个图表来展示不同之处。
chull_diff = img_as_float(chull.copy())
chull_diff[image] = 2
fig, ax = plt.subplots()
ax.imshow(chull_diff, cmap=plt.cm.gray)
ax.set_title('Difference')
plt.show()

脚本的总运行时间: (0分0.174秒)