active-contour

active_contour

skimage.segmentation.active_contour(image, snake, alpha=0.01, beta=0.1, w_line=0, w_edge=1, gamma=0.01, bc='periodic', max_px_move=1.0, max_iterations=2500, convergence=0.1) [source]

Active contour model.

Active contours by fitting snakes to features of images. Supports single and multichannel 2D images. Snakes can be periodic (for segmentation) or have fixed and/or free ends.

Parameters:

image : (N, M) or (N, M, 3) ndarray

Input image.

snake : (N, 2) ndarray

Initialisation coordinates of snake. For periodic snakes, it should not include duplicate endpoints.

alpha : float, optional

Snake length shape parameter. Higher values makes snake contract faster.

beta : float, optional

Snake smoothness shape parameter. Higher values makes snake smoother.

w_line : float, optional

Controls attraction to brightness. Use negative values to attract to dark regions.

w_edge : float, optional

Controls attraction to edges. Use negative values to repel snake from edges.

gamma : float, optional

Explicit time stepping parameter.

bc : {‘periodic’, ‘free’, ‘fixed’}, optional

Boundary conditions for worm. ‘periodic’ attaches the two ends of the snake, ‘fixed’ holds the end-points in place, and’free’ allows free movement of the ends. ‘fixed’ and ‘free’ can be combined by parsing ‘fixed-free’, ‘free-fixed’. Parsing ‘fixed-fixed’ or ‘free-free’ yields same behaviour as ‘fixed’ and ‘free’, respectively.

max_px_move : float, optional

Maximum pixel distance to move per iteration.

max_iterations : int, optional

Maximum iterations to optimize snake shape.

convergence: float, optional

Convergence criteria.

Returns:

snake : (N, 2) ndarray

Optimised snake, same shape as input parameter.

References

[R347] Kass, M.; Witkin, A.; Terzopoulos, D. “Snakes: Active contour models”. International Journal of Computer Vision 1 (4): 321 (1988).

Examples

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

Create and smooth image:

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

Initiliaze spline:

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

Fit spline to image:

>>> snake = active_contour(img, init, w_edge=0, w_line=1) 
>>> dist = np.sqrt((45-snake[:, 0])**2 +(35-snake[:, 1])**2) 
>>> int(np.mean(dist)) 
25
doc_scikit_image
2017-01-12 17:20:02
Comments
Leave a Comment

Please login to continue.