# Active contour models for shape tracking

An overview of active shape models for object tracking in image analysis

When we are trying to track an object, one way we can do this is by following the shape of the object between frames. To do this, we need a way of representing the shape of an object in an image. For this purpose we can use a family of models called active shape or active contour models.

## Active contour models

Active contour models have two main components which allow them to pick out an object. Features such as edges and corners help us to delineate objects in the scene; they allow us to pick out a boundary around an object. If we are building a model to represent shape, using features such as these are helpful to incorporate as an external energy, or external constraint. These parts of the model examine the image data to help adjust the curve to the shape of the object.

The second main component of the model is a representation of the boundary curve itself. The model must be able to describe such a curve, as well as adjust it in response to changes in the object shape, or to allow it to adjust to fit an object initially. Such properties are represented as the internal energy, or internal constraints. They control how flexible the curve is, and how it is able to move.

Depending on the application, the nature of these energies may be different, but, typically, the external energy (otherwise known as an image energy) is drawn to edge features in an image, and the internal energy favours a smooth, well-represented curve. By well represented, we typically mean any key or control points which help describe the shape are regularly space out, rather than bunching up, which can cause knotting-type artefacts.

Left: Initial curve.
Right: the curve fitted to the image data, balancing the pull of edges in the image against how much the curve is allowed to bend.
Control points, which are used in the mathematical model of the curve, are marked as red circles. One of the internal constraints keeps these points evenly spread around the leaf.
Note how in the figure on the right the stalk of the leaf is excluded from the boundary. This is because the smoothness constraint in is outweighing the image energy which controls how much the contour model is allowed to bend. The model balances this energy with the curve finally fitting to the main leaf, but not closely fitting the stalk. By adjusting the weight on the various energies, it would be possible to achieve a better fit around the stalk as well, if desired – though omitting the stalk maybe beneficial for many calculations in this example. Therefore, some tuning of parameters is required with such models to ensure a good fit for the image data to hand.

## Initialising active contour models

In the figure above, the left-hand curve represents where the model starts – where it is initialised. This can be by hand, for example with a user loosely drawing around the initial shape. The curve is then allowed to settle onto the object. If the edge of the object is within range of the curve, the control points of the curve become attracted to the edge, analogous to a magnetic force. One quirk of active contour models is that if edges fall outside the range of the model, there will be no attraction to object edges and the curve will not move. In the case of the left-hand figure scenario above, this can be overcome by making the curve behave as if it is elastic. To do this, we can add an additional internal energy which tries to shrink the curve, much like a rubber band. It can be designed so that on contact with an object, this energy is overcome by the edge forces.

## Tracking with active contour models

Utilizing the property of the curve model to settle to the shape of an object, this can also be used to adapt to an object which changes shape, or even an object that moves. Using an initialisation from a previous timepoint, we can position the curve in the next frame of a video, and allow it to settle again. As long so the movement (or shape change) between video frames is not too great, we can use an active contour as a tracker, to follow a shape’s contour between timepoints.
Left (timepoint 1): The contour from the previous frame is overlaid on the current frame image. The active contour model does not yet line up with the shape.
Right: After allowing the active contour model to run and settle, the shape model is now a good fit to the object boundary.

• The original article on active contour models Kass, M., Witkin, A. & Terzopoulos, D. Snakes: Active contour models. Int J Comput Vision 1, 321–331 (1988). https://doi.org/10.1007/BF00133570

You can find lots of example implementations of these models in many programming languages.