备注
单击 here 下载完整的示例代码或通过活页夹在浏览器中运行此示例
轮廓线查找¶
我们使用行进平方方法来寻找图像中的恒定值轮廓。在……里面 skimage.measure.find_contours
,阵列值被线性内插,以提供更好的输出轮廓精度。与图像边缘相交的轮廓是开放的;其他所有轮廓都是闭合的。
这个 marching squares algorithm 是行进立方体算法的特例(Lorensen,William and Harvey E.Cline.行进立方体:一种高分辨率三维曲面构建算法《计算机图形学》1987年7月21日(4),第163-170页)。

import numpy as np
import matplotlib.pyplot as plt
from skimage import measure
# Construct some test data
x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j]
r = np.sin(np.exp((np.sin(x)**3 + np.cos(y)**2)))
# Find contours at a constant value of 0.8
contours = measure.find_contours(r, 0.8)
# Display the image and plot all contours found
fig, ax = plt.subplots()
ax.imshow(r, cmap=plt.cm.gray)
for contour in contours:
ax.plot(contour[:, 1], contour[:, 0], linewidth=2)
ax.axis('image')
ax.set_xticks([])
ax.set_yticks([])
plt.show()
脚本的总运行时间: (0分0.050秒)