当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。