# Snakes

## Theory

When the snake coordinate vector is defined parametrically as $v(s) = (x(s), y(s))$, the total energy of the snake is defined as $$ E^*_{snake} = \int E_{snake}(v(s))ds = \int E_{int}(v(s))ds + \int E_{ext}(v(s))ds $$ $$ E_{int} = E_{cont} + E_{curv} $$ The two energies are given by the first and second derivatives of the contour v(s). $$ E_{ext} = -|| \nabla I || $$

## Discrete implementation

Model the contour as $ c = {p1,p2,...,pN} $, now the cost function becomes $$ E = \sum_{i=1}^{N} (\alpha_i E_{cont} + \beta_i E_{curv} + \gamma_i E_{image}) $$

- The continuity energy can be defined in terms of the distance between points along the snake, as compared to the average distance between neighboring points. Thus, this term will seek to keep points along the snake as close together as possible.
- The curvature energy is nothing but the second derivative at each point along the snake. Finally, each of these energies are normalized by division with the largest value in any given neighborhood.
- A pre-processing step is required prior to computing the image gradient. Gaussian blurring is applied as a pre-processing step. This ensures a greater range for the deformable snake to latch onto image contours.
- Normalizing the gradient magnitude can lead to detection of spurious or weak edges and should be avoided.