Functions to align instances.

Usually you’ll want to

  1. find out the skeleton edge to use for aligning instances,

  2. align all instances using this edge in the skeleton,

  3. calculate mean/std for node locations of aligned instances.

For step (1), we use the most “stable” edge (smallest std in length) for the set of instances which has a (mean) length above some threshold. Usually this will be something like [head -> thorax], i.e., an edge between two body parts which are relatively fixed relative to each other, and thus work well as an axis for aligning all the instances.

Steps (2) and (3) are fairly straightforward: we calculate angle of the edge found in step (1) for each instance, then rotate each instance accordingly, then calculate mean/standard deviation for each node in the resulting matrix.

Note that all these functions are vectorized and work on matrices with shape (instances, nodes, 2), where 2 corresponds to (x, y) for each node.

After we have a “mean” instance (i.e., an instance with all points at mean of other, aligned instances), the “mean” instance can then itself be aligned with another instance using the align_instance_points function. This is useful so we can use “mean” instance to add “default” points to an instance which doesn’t yet have all points)., target_points_array)[source]#

Transforms source for best fit on to target. numpy.ndarray, node_a: int, node_b: int, rotate_on_node_a: bool = False) numpy.ndarray[source]#

Rotates every instance so that line from node_a to node_b aligns. numpy.ndarray, min_stable_dist: float = 4.0) numpy.ndarray[source]#

Gets most stable pair of nodes and aligned instances along these nodes. List[sleap.instance.Instance]) numpy.ndarray[source]#

Returns single (instance, node, 2) matrix with points for all instances. numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray][source]#

Returns mean and standard deviation for every node given aligned points. numpy.ndarray, min_dist: float = 0.0) Tuple[int, int][source]#

Returns pair of nodes which are at stable distance (over min threshold). numpy.ndarray, node_names, min_dist: float = 0.0)[source]#

Returns sorted list of node pairs with mean and standard dev distance. List[sleap.instance.Instance]) numpy.ndarray[source]#

Returns mean of aligned points for instances.