Dist Stitcher

class byotrack.implementation.refiner.stitching.dist_stitcher.DistStitcher(dist: Callable[[Iterable[ndarray], Collection[Track]], ndarray], eta=inf)

Bases: Refiner

Track stitching using distance minimization

dist

Callable that compute the distance between each track

Type:

Dist

eta

Soft threshold in LAP solving (See pylapy) Default: inf (No soft thresholding)

Type:

float

lap_solver

Solver of the assignment problem

Type:

LapSolver

run(video: Iterable[ndarray], tracks: Collection[Track]) List[Track]

Run the refiner on a whole video

Parameters:
  • video (Iterable[np.ndarray]) – Sequence of frames (video) Each array is expected to have a shape (H, W, C)

  • tracks (Collection[byotrack.Track]) – Tracks of particles

Returns:

Refined tracks of particles

Return type:

Collection[byotrack.Track]

static merge(tracks: Collection[Track], links: ndarray) List[Track]

Merge tracks following the given links

Parameters:
  • tracks (Collection[byotrack.Track]) – Tracks to merge

  • links (np.ndarray) – Links between tracks. Each link is a pair of track indices Shape: (L, 2), dtype: int

Returns:

Merged tracks. Note that in a merge track there is a probably a unknown gap

between the two original tracks where the position of the merge track is set to nan by default

Return type:

List[byotrack.Track]

static skip_computation(tracks: Collection[Track], max_overlap: int, max_dist: float, max_gap: int) Tensor

Compute a boolean mask that indicate which distance should be skipped

Based on simple rules, prevents the computation of most distances. Let i, j two tracks:

  1. i ends at most max_gap frames before j starts

  2. i ends at most max_overlap frames after j starts

  3. i last position is at most at max_dist from j first position

Parameters:
  • tracks (Collection[byotrack.Track]) – Current set of tracks

  • max_overlap (int) – Cannot stitch tracks that overlap more than max_overlap

  • max_dist (float) – Cannot stich track i and track j if the last position of i and first position of j are farther than max_dist (ignored if max_dist <= 0)

  • max_gap (int) – Cannot stich track i and track j if i ended more than max_gap frame before j started (ignored if max_gap <= 0)

Returns:

Boolean tensor that indicates True when the dist computation should be skipped

Return type:

torch.Tensor

static normalize(dist: ndarray) ndarray

Normalize a distance matrix into [0, 1]

Parameters:

dist (np.ndarray) – Distance matrix to normalize Shape: (N, N), dtype: float32

Returns:

Normalized distance matrix

Shape: (N, N), dtype: float32

Return type:

np.ndarray