# Tracking parameters

This section details how to select the relevant tracking features to be included in the cost function and how to tune them.

## How it works

FastTrack uses the so-called Hungarian method to solve the assignment problem of each object between two frames. This method is based on minimizing the global cost of the association pairs of objects.

### Cost function

The cost is calculated from a cost function that can be constructed from several parameters, in the following, i is indexing the image n, and j the image n + 1:

- The distance $d{ij} = \sqrt{(x_i - x_j)^2 + (y_i - y_j)^2}$
- The angle $a_{ij} = min(\theta_i - \theta_j)$
- The area $ar_{ij} = abs(area_i - area_j)$
- The perimeter $p_{ij} = abs(perimeter_i - perimeter_j)$

The relative weight of these contributions to the cost function are set by 4 normalization parameters:

These parameters can be set to 0 to cancel one or several tracking feature from the cost computation. All these features are not always relevant and has to be chosen carrefully for the best tracking accuracy. For example, for tracking circles of radius r, and squares of the same area moving at 10px/image, it is best to set

For tracking fish of the same size, travelling at 35px/image, doing small reorientation of 20°, it is best to set

For tracking fish of different size, travelling at 35px/image, doing small reorientation of 20°, with size difference of 100px it is best to set

The best way to set the parameter is to first set the normalization parameters to the mean of the variable, .ie the typical change between two consecutive images:

- $D = mean(d_{ij})$ where i and j are the same object.
- $A = mean(a_{ij})$ where i and j are the same object.
- $AR = mean(ar_{ij})$ where i and j are the same object.
- $P = mean(p_{ij})$ where i and j are the same object. In this case, each tracking feature has the same contribution to the cost. To tune the cost function by weighting more (resp. less) a tracking feature, decrease (resp. increase) the normalization parameter of this feature, or increase (resp. decrease) all the normalization parameters of the others.

### Memory and distance

A parameter of memory named maximal time can be set to account for disappearing objects. If the maximal time is set to m, one object can only disappear during m image. If it reappears after, it will be considered as a new object.

To speed-up the tracking, the maximal distance (L) parameter sets an infinite cost for all the pairs of objects to such as $d_{ij} > L$. In practice, L is corresponding to the maximal distance an object can disappear.

### Spot

The spot to track will determine if the distance and the angular difference will be calculated from the head, the tail, or the body of the object. Area and perimeter are always computed from the body. Head is defined as the bigger half of the object, separated alongside the object's minor axis.

## Conclusion

Setting the tracking parameters can be tedious. It can be best achieved by trials and errors (see the Preview option in the Interactive panel). to summarize:

- Choose the right tracking features.
- Set the normalization parameters equal to the tracking feature's std, ie, the typical value change.
- Tune the normalization parameters to increase or decrease the relative weight between each contribution.