當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python skimage.segmentation.active_contour用法及代碼示例

用法:

skimage.segmentation.active_contour(image, snake, alpha=0.01, beta=0.1, w_line=0, w_edge=1, gamma=0.01, max_px_move=1.0, max_num_iter=2500, convergence=0.1, *, boundary_condition='periodic', coordinates='rc')

主動輪廓模型。

通過將蛇擬合到圖像的特征來激活輪廓。支持單通道和多通道 2D 圖像。蛇可以是周期性的(用於分段)或具有固定和/或自由端。輸出蛇與輸入邊界的長度相同。由於點的數量是恒定的,請確保初始蛇有足夠的點來捕捉最終輪廓的細節。

參數

image(N, M) 或 (N, M, 3) ndarray

輸入圖像。

snake(N, 2) 數組

初始蛇坐標。對於周期性邊界條件,端點不得重複。

alpha浮點數,可選

蛇長形狀參數。較高的值使蛇收縮更快。

beta浮點數,可選

蛇平滑形狀參數。較高的值使蛇更平滑。

w_line浮點數,可選

控製對亮度的吸引力。使用負值來吸引黑暗區域。

w_edge浮點數,可選

控製對邊的吸引力。使用負值從邊擊退蛇。

gamma浮點數,可選

顯式時間步進參數。

max_px_move浮點數,可選

每次迭代移動的最大像素距離。

max_num_iterint 可選

優化蛇形的最大迭代次數。

convergence浮點數,可選

收斂標準。

boundary_condition字符串,可選

輪廓的邊界條件。可以是‘periodic’, ‘free’, ‘fixed’、“free-fixed”或“fixed-free”之一。 ‘periodic’ 連接蛇的兩端,‘fixed’ 將 end-points 固定到位,‘free’ 允許末端自由移動。 ‘fixed’ and ‘free’可以通過解析‘fixed-free’、‘free-fixed’進行組合。解析‘fixed-fixed’或‘free-free’分別產生與‘fixed’ and ‘free’相同的行為。

coordinates{‘rc’},可選

此選項僅出於兼容性目的而保留,無效。它是在 0.16 中引入的,帶有 'xy' 選項,但從 0.18 開始,隻有 'rc' 選項有效。坐標必須以row-column 格式設置。

返回

snake(N, 2) 數組

優化的蛇形,與輸入參數的形狀相同。

其他參數

max_iterationsDEPRECATED

已棄用以支持max_num_iter。

參考

1

Kass, M.; Witkin, A.; Terzopoulos, D. “Snakes: Active contour models”. International Journal of Computer Vision 1 (4): 321 (1988). DOI:10.1007/BF00133570

例子

>>> from skimage.draw import circle_perimeter
>>> from skimage.filters import gaussian

創建和平滑圖像:

>>> img = np.zeros((100, 100))
>>> rr, cc = circle_perimeter(35, 45, 25)
>>> img[rr, cc] = 1
>>> img = gaussian(img, 2, preserve_range=False)

初始化樣條:

>>> s = np.linspace(0, 2*np.pi, 100)
>>> init = 50 * np.array([np.sin(s), np.cos(s)]).T + 50

擬合樣條到圖像:

>>> snake = active_contour(img, init, w_edge=0, w_line=1, coordinates='rc')  
>>> dist = np.sqrt((45-snake[:, 0])**2 + (35-snake[:, 1])**2)  
>>> int(np.mean(dist))  
25

相關用法


注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.segmentation.active_contour。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。