輪廓查找#

我們使用行進方塊方法在影像中查找恆定值的輪廓。在 skimage.measure.find_contours 中,陣列值會線性內插,以提供更好的輸出輪廓精度。與影像邊緣相交的輪廓是開放的;所有其他輪廓都是封閉的。

行進方塊演算法是行進立方體演算法的一個特例(Lorensen,William 和 Harvey E. Cline. Marching Cubes:高解析度 3D 曲面建構演算法。Computer Graphics SIGGRAPH 87 Proceedings)21(4) 1987 年 7 月,第 163-170 頁)。

plot contours
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.205 秒)

由 Sphinx-Gallery 產生的圖庫