**Name**

**mac_snakes** Maximizing Average Contrast Snakes for contour detection

**Command Synopsis**

**mac_snakes** [-p *power*] [-n *niter*] [-s *step*] [-v] [-V *V*] *u* *in* *out*

-ppower: g(s)= | s | power (default power=1.0)

-nniter: number of iterations (default 1000)

-sstep: evolution step (default 1.0)

-v : verbose mode

-VV: select video mode and specify zoom (e.g. 2)

u: input Fimage

in: input curves (Dlists)

out: output curves (modified input)

**Function Summary**

Dlists mac_snakes (u , in , niter , step , power , v , V )

Fimage u ;

Dlists in ;

int *niter ;

float *V ;

double *step , *power ;

char *v ;

**Description**

This module implements the Kimmel and Bruckstein snake model [KB02] for contour detection (or optimization). Its goal is to maximize with respect with (an arclength parameterized curve) the average contrast

This module only implements the case
*g*(*s*) = | *s*|^{power}, but it could be easily adapted to more general
functions *g*. The influence of the
choice of *g* is discussed in [DMM03].
The default is *g*(*s*) = | *s*|, but powers smaller than 1 could be preferred
in order to reduce even more the sensitivity to the image contrast.

The numerical scheme is based on a gradient descent (with step *step*)
associated to a discrete version of *E*() (see the description
below, and [DMM03] for a complete discussion and full details).
An input Fimage (*u*) and an initial set *in*
of curves (Dlists) should be provided
to the module, which outputs a new (final) set of curves *out*
after *niter* iterations (`-n`

option). Intermediate
states can be monitored by printing the energy evolution (with
`-v`

option) or visually with the `-V`

option followed by
a zoom factor (try 2 for example). Note that the number of points of
each curve is kept constant during the evolution,
so that an appropriate (fine enough) sampling
of each initial curve is needed: rough polygons will not do in general!

Due to their sensitivity to initial conditions, snakes models should be used for interactive contour optimization rather than for contour detection. To obtain good results, one should

- choose an initial contour close enough to the optimal solution seeked;
- used a smoothed initial image (obtained for example with
`fsepconvol`

or`amss`

) in order to avoid local maxima of the snakes model; - use a correctly sampled initial contour (if used,
`readpoly`

should be followed by`gass`

); - select an appropriate value for the gradent step (
`-s`

option), which can easily go from 0.01 to more than 1000.

An example is given by the following sequence of commands:

circle -r 20 -n 100 c fkzrt c c 1 0 115 170 fkview -s -b cimage c & fsepconvol -g 1 cimage u mac_snakes -V 2 -s 1 -n 3000 u c out

For an interactive choice of the initial contour, the first two lines may be replaced by

readpoly cimage c gass -e 2 c c(type 'q' after drawing manually the initial contour).

For a non-Euclidean
parameterization
(*p*) : [*a*, *b*]*I**R*^{2}, the energy we want to
maximize writes

To compute the evolution of the snake, we use a two-steps iterative scheme.

- The first step consists in a reparameterization of the snake
according to arc length. It can be justified in several ways :
aside from bringing stability to the scheme, it guarantees a
*geometric*evolution of the curve, it ensures an homogeneous estimate of the energy, and it prevents singularities to appear too easily. However, we do not prevent self-intersections of the curve. - The second step is simply a gradient evolution with a fixed step.
If (
*M*_{i}^{n})_{i}represents the (polygonal) snake at iteration*n*and ()_{i}its renormalized version after step 1, then we set*M*_{i}^{n+1}= +*step*^{ . }*F*.

**See Also**

**Version 1.0**

Last Modification date : Tue Apr 8 04:08:35 2003

**Author**

Lionel Moisan