align
sleap.info.align
¶
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).
Functions:
| Name | Description |
|---|---|
align_instance_points |
Transforms source for best fit on to target. |
align_instances |
Rotates every instance so that line from node_a to node_b aligns. |
align_instances_on_most_stable |
Gets most stable pair of nodes and aligned instances along these nodes. |
get_instances_points |
Returns single (instance, node, 2) matrix with points for all instances. |
get_mean_and_std_for_points |
Returns mean and standard deviation for every node given aligned points. |
get_most_stable_node_pair |
Returns pair of nodes which are at stable distance (over min threshold). |
get_stable_node_pairs |
Returns sorted list of node pairs with mean and standard dev distance. |
get_template_points_array |
Returns mean of aligned points for instances. |
align_instance_points(source_points_array, target_points_array)
¶
Transforms source for best fit on to target.
Source code in sleap/info/align.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
align_instances(all_points_arrays, node_a, node_b, rotate_on_node_a=False)
¶
Rotates every instance so that line from node_a to node_b aligns.
Source code in sleap/info/align.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
align_instances_on_most_stable(all_points_arrays, min_stable_dist=4.0)
¶
Gets most stable pair of nodes and aligned instances along these nodes.
Source code in sleap/info/align.py
133 134 135 136 137 138 139 140 141 142 143 | |
get_instances_points(instances)
¶
Returns single (instance, node, 2) matrix with points for all instances.
Source code in sleap/info/align.py
246 247 248 249 250 251 252 253 254 255 256 257 | |
get_mean_and_std_for_points(aligned_points_arrays)
¶
Returns mean and standard deviation for every node given aligned points.
Source code in sleap/info/align.py
146 147 148 149 150 151 152 153 154 155 | |
get_most_stable_node_pair(all_points_arrays, min_dist=0.0)
¶
Returns pair of nodes which are at stable distance (over min threshold).
Source code in sleap/info/align.py
85 86 87 88 89 90 | |
get_stable_node_pairs(all_points_arrays, node_names, min_dist=0.0)
¶
Returns sorted list of node pairs with mean and standard dev distance.
Source code in sleap/info/align.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
get_template_points_array(instances)
¶
Returns mean of aligned points for instances.
Source code in sleap/info/align.py
260 261 262 263 264 265 266 267 268 | |