Functions to align instances.
Usually you’ll want to
find out the skeleton edge to use for aligning instances,
align all instances using this edge in the skeleton,
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).
- sleap.info.align.align_instance_points(source_points_array, target_points_array)#
Transforms source for best fit on to target.
- sleap.info.align.align_instances(all_points_arrays: numpy.ndarray, node_a: int, node_b: int, rotate_on_node_a: bool = False) numpy.ndarray #
Rotates every instance so that line from node_a to node_b aligns.
- sleap.info.align.align_instances_on_most_stable(all_points_arrays: numpy.ndarray, min_stable_dist: float = 4.0) numpy.ndarray #
Gets most stable pair of nodes and aligned instances along these nodes.
- sleap.info.align.get_instances_points(instances: List[sleap.instance.Instance]) numpy.ndarray #
Returns single (instance, node, 2) matrix with points for all instances.
- sleap.info.align.get_mean_and_std_for_points(aligned_points_arrays: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray] #
Returns mean and standard deviation for every node given aligned points.
- sleap.info.align.get_most_stable_node_pair(all_points_arrays: numpy.ndarray, min_dist: float = 0.0) Tuple[int, int] #
Returns pair of nodes which are at stable distance (over min threshold).
- sleap.info.align.get_stable_node_pairs(all_points_arrays: numpy.ndarray, node_names, min_dist: float = 0.0)#
Returns sorted list of node pairs with mean and standard dev distance.