Motivation
In computer vision, contour models describe the boundaries of shapes in an image. Snakes in particular are designed to solve problems where the approximate shape of the boundary is known. By being a deformable model, snakes can adapt to differences and noise in stereo matching and motion tracking. Additionally, the method can findEnergy formulation
A simple elastic snake is defined by a set of ''n'' points for , the internal elastic energy term , and the external edge-based energy term . The purpose of the internal energy term is to control the deformations made to the snake, and the purpose of the external energy term is to control the fitting of the contour onto the image. The external energy is usually a combination of the forces due to the image itself and the constraint forces introduced by the user The energy function of the snake is the sum of its external energy and internal energy, or :Internal energy
The internal energy of the snake is composed of the continuity of the contour and the smoothness of the contour . : This can be expanded as : where and are user-defined weights; these control the internal energy function's sensitivity to the amount of stretch in the snake and the amount of curvature in the snake, respectively, and thereby control the number of constraints on the shape of the snake. In practice, a large weight for the continuity term penalizes changes in distances between points in the contour. A large weight for the smoothness term penalizes oscillations in the contour and will cause the contour to act as a thin plate.Image energy
Energy in the image is some function of the features of the image. This is one of the most common points of modification in derivative methods. Features in images and images themselves can be processed in many and various ways. For an image , lines, edges, and terminations present in the image, the general formulation of energy due to the image is : where , , are weights of these salient features. Higher weights indicate that the salient feature will have a larger contribution to the image force.Line functional
The line functional is the intensity of the image, which can be represented as : The sign of will determine whether the line will be attracted to either dark lines or light lines. Some smoothing or noise reduction may be used on the image, which then the line functional appears as :Edge functional
The edge functional is based on the image gradient. One implementation of this is : A snake originating far from the desired object contour may erroneously converge to some local minimum. Scale space continuation can be used in order to avoid these local minima. This is achieved by using a blur filter on the image and reducing the amount of blur as the calculation progresses to refine the fit of the snake. The energy functional using scale space continuation is : where is a Gaussian with standard deviation . Minima of this function fall on the zero-crossings of which define edges as per Marr–Hildreth theory.Termination functional
Curvature of level lines in a slightly smoothed image can be used to detect corners and terminations in an image. Using this method, let be the image smoothed by : with gradient angle : unit vectors along the gradient direction : and unit vectors perpendicular to the gradient direction : The termination functional of energy can be represented as :Constraint energy
Some systems, including the original snakes implementation, allowed for user interaction to guide the snakes, not only in initial placement but also in their energy terms. Such constraint energy can be used to interactively guide the snakes towards or away from particular features.Optimization through gradient descent
Given an initial guess for a snake, the energy function of the snake is iteratively minimized. Gradient descent minimization is one of the simplest optimizations which can be used to minimize snake energy. Each iteration takes one step in the negative gradient of the point with controlled step size to find local minima. This gradient-descent minimization can be implemented as : Where is the force on the snake, which is defined by the negative of the gradient of the energy field. : Assuming the weights and are constant with respect to , this iterative method can be simplified to :Discrete approximation
In practice, images have finite resolution and can only be integrated over finite time steps . As such, discrete approximations must be made for practical implementation of snakes. The energy function of the snake can be approximated by using the discrete points on the snake. : Consequentially, the forces of the snake can be approximated as : Gradient approximation can be done through any finite approximation method with respect to ''s'', such as Finite difference.Numerical instability due to discrete time
The introduction of discrete time into the algorithm can introduce updates which the snake is moved past the minima it is attracted to; this further can cause oscillations around the minima or lead to a different minima being found. This can be avoided through tuning the time step such that the step size is never greater than a pixel due to the image forces. However, in regions of low energy, the internal energies will dominate the update. Alternatively, the image forces can be normalized for each step such that the image forces only update the snake by one pixel. This can be formulated as : where is near the value of the pixel size. This avoids the problem of dominating internal energies that arise from tuning the time step.Laurent D. Cohen, On active contour models and balloons, CVGIP: Image Understanding, Volume 53, Issue 2, March 1991, Pages 211–218, ISSN 1049-9660,Numerical instability due to discrete space
The energies in a continuous image may have zero-crossing that do not exist as a pixel in the image. In this case, a point in the snake would oscillate between the two pixels that neighbor this zero-crossing. This oscillation can be avoided by using interpolation between pixels instead of nearest neighbor.Some variants of snakes
The default method of snakes has various limitation and corner cases where the convergence performs poorly. Several alternatives exist which addresses issues of the default method, though with their own trade-offs. A few are listed here.GVF snake model
The gradient vector flow (GVF) snake modelC. Xu and J.L. Prince, "Gradient Vector Flow: A New External Force for Snakes," Proc. IEEE Conf. on Comp. Vis. Patt. Recog. (CVPR), Los Alamitos: Comp. Soc. Press, pp. 66–71, June 1997, http://iacl.ece.jhu.edu/pubs/p087c.pdf addresses two issues with snakes: *poor convergence performance for concave boundaries *poor convergence performance when snake is initialized far from minimum In 2D, the GVF vector field minimizes the energy functional : where is a controllable smoothing term. This can be solved by solving the Euler equations : : This can be solved through iteration towards a steady-state value. : : This result replaces the default external force. : The primary issue with using GVF is the smoothing term causes rounding of the edges of the contour. Reducing the value of reduces the rounding but weakens the amount of smoothing.The balloon model
The balloon model addresses these problems with the default active contour model: * The snake is not attracted to distant edges. * The snake will shrink inwards if no substantial images forces are acting upon it. * a snake larger than the minima contour will eventually shrink into it, but a snake smaller than the minima contour will not find the minima and instead continue to shrink. The balloon model introduces an inflation term into the forces acting on the snake : where is the normal unitary vector of the curve at and is the magnitude of the force. should have the same magnitude as the image normalization factor and be smaller in value than to allow forces at image edges to overcome the inflation force. Three issues arise from using the balloon model: *Instead of shrinking, the snake expands into the minima and will not find minima contours smaller than it. *The outward force causes the contour to be slightly larger than the actual minima. This can be solved by decreasing the balloon force after a stable solution has been found. *The inflation force can overpower forces from weak edges, amplifying the issue with snakes ignoring weaker features in an image.Diffusion snakes model
The diffusion snake model addresses the sensitivity of snakes to noise, clutter, and occlusion. It implements a modification of theGeometric active contours
Geometric active contour, or geodesic active contour (GAC)Geodesic Active Contours, V. Caselles, R. Kimmel, G. Sapiro http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.21.2196 or conformal active contours employs ideas from Euclidean curve shortening evolution. Contours split and merge depending on the detection of objects in the image. These models are largely inspired by level sets, and have been extensively employed in medical image computing. For example, the gradient descent curve evolution equation of GAC is : where is a halting function, ''c'' is a Lagrange multiplier, is the curvature, and is the unit inward normal. This particular form of curve evolution equation is only dependent on the velocity in the normal direction. It therefore can be rewritten equivalently in an Eulerian form by inserting the level set function into it as follows : This simple yet powerful level-set reformation enables active contours to handle topology changes during the gradient descent curve evolution. It has inspired tremendous progress in the related fields, and using numerical methods to solve the level-set reformulation is now commonly known as the level-set method. Although the level set method has become quite a popular tool for implementing active contours, Wang and Chan argued that not all curve evolution equations should be ''directly'' solved by it. More recent developments in active contours address modeling of regional properties, incorporation of flexible shape priors and fully automatic segmentation, etc. Statistical models combining local and global features have been formulated by Lankton andRelations to graph cuts
Graph cuts, or max-flow/min-cut, is a generic method for minimizing a particular form of energy called Markov random field (MRF) energy. The Graph cuts method has been applied to image segmentation as well, and it sometimes outperforms the level set method when the model is MRF or can be approximated by MRF.See also
* Boundary vector fieldReferences
External links
Sample code