Algorithm

First Canny edge detection is performed on the image and a B-Spline is calculated from the user's original placement of the control points. Then a minimization is applied.

Canny Edge Detection:

1. The image is smoothed with a gaussian smoothing filter Gsigma(i,j) of user specified sigma.

          S(u,v) = sum(i=-n to n) sum(j=-n to n) (Gsigma(i,j)I(u-i,v-j)) 

2. The gradient Del(S), of the smoothed image is then computed at each pixel.

          Del(S) =   | S(u+1,v)-S(u,v) |
                     | S(u,v+1)-S(u,v) | 

3. Edge elements are placed at pixels where |Del(S)| is a local maximal in the edge directions and is above a user specified threshold.

B-Splines

A cubic B-spline is specified by m+1 control points Q0,Q1,...Qm and comprises m-2 cubic polynomial curve segments. Each segment of the B-Spline is calculated from its 4 closest control points and the joining points between each segment are called knots. The equation for each curve segment is:

                                            | -1  3 -3  1 | |Q[i-3]|
                                            |  3 -6  3  0 | |Q[i-2]|
                 Ui(s) = (1/6)[s^3 s^2 s 1] | -3  0  3  3 | |Q[i-1]|
                                            |  1  4  1  0 | | Q[i] |
                        
                      
                        for 0<=s<1 and 3<=i<=m.


B-Splines are ideal to use as active contours since they are continuous at each point and knot. The number of control points controls the flexibility or curvature of the spline. They are also nice in that they exhibit local control, since modifying a single control points only causes a small part of the contour to change.

Minimization:

1. Control points are placed by the user nearby to some object of interest.

2. The initial B-spline segments are calculated from the control points.

3. Sample points along each spline segment are selected (20 were used).

4. The distance normal to the spline from each sample point to the nearest edge is calculated.

Repeat {

5. Cycle through each control point. Each control point contributes to the calculation of 4 spline segments.

6. For each pixel in an NxN neighborhood surrounding the current control point:

       a. Recalculate the 4 splines the control point contributes to if the 
         control point were to be moved there.
       b. Recalculate the distances of the sample points along the 4 splines 
         to the closest edge (in the normal direction to the spline).

7.

       a. Move the control point to the neighborhood point which has the 
         smallest sum of distances between sample points and edge points.
       b. If the control point moves add one to the number of control points 
         moved in this iteration. 

} while ( less than n% (as specified by user) of control points have moved )