instance_utils
sleap.sleap_io_adaptors.instance_utils
¶
Helper functions for sleap_io.Instance objects.
Functions:
| Name | Description |
|---|---|
bounding_box |
Return bounding box containing all points in |
fill_missing |
Add points for skeleton nodes that are missing in the instance. |
get_centroid |
Return instance centroid as an array of |
get_nodes_from_instance |
Return nodes that have been labelled (non-nan) for this instance. |
instance_get_points_array |
Get points array for backward compatibility. |
instance_get_scores |
Get point-wise scores for backward compatibility. |
instance_same_pose_as_compat |
Compare poses between instances for backward compatibility. |
node_points |
Return a list of (node, point) tuples for all labeled points. |
predicted_instance_from_numpy_compat |
Create PredictedInstance from numpy array with backward compatibility. |
bounding_box(instance)
¶
Return bounding box containing all points in [y1, x1, y2, x2] format.
Source code in sleap/sleap_io_adaptors/instance_utils.py
fill_missing(instance, max_x=None, max_y=None)
¶
Add points for skeleton nodes that are missing in the instance.
This is useful when modifying the skeleton so the nodes appear in the GUI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Instance
|
sleap_io Instance object |
required |
max_x
|
Optional[float]
|
If specified, make sure points are not added outside of valid range. |
None
|
max_y
|
Optional[float]
|
If specified, make sure points are not added outside of valid range. |
None
|
Returns:
| Type | Description |
|---|---|
|
Modified instance with missing points filled |
Source code in sleap/sleap_io_adaptors/instance_utils.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
get_centroid(instance)
¶
Return instance centroid as an array of (x, y) coordinates.
Notes
This computes the centroid as the median of the visible points.
Source code in sleap/sleap_io_adaptors/instance_utils.py
get_nodes_from_instance(instance)
¶
Return nodes that have been labelled (non-nan) for this instance.
Source code in sleap/sleap_io_adaptors/instance_utils.py
instance_get_points_array(instance)
¶
Get points array for backward compatibility.
This provides backward compatibility for the missing points_array attribute. Maps instance.points_array to instance.numpy() or instance.points["xy"].
Source code in sleap/sleap_io_adaptors/instance_utils.py
instance_get_scores(instance)
¶
Get point-wise scores for backward compatibility.
This provides backward compatibility for the missing scores attribute. Maps instance.scores to point-wise scores from instance.points["score"] if available, or falls back to instance.score for PredictedInstance.
Source code in sleap/sleap_io_adaptors/instance_utils.py
instance_same_pose_as_compat(instance1, instance2)
¶
Compare poses between instances for backward compatibility.
This provides a safe way to compare instance poses that handles array comparison ambiguity issues.
Source code in sleap/sleap_io_adaptors/instance_utils.py
node_points(instance)
¶
Return a list of (node, point) tuples for all labeled points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
sleap_io Instance object |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple[Node, ndarray]]
|
List of (Node, point_data) tuples where point_data is [x, y, visible, complete] |
Source code in sleap/sleap_io_adaptors/instance_utils.py
predicted_instance_from_numpy_compat(points, skeleton, point_confidences=None, instance_score=None, track=None, **kwargs)
¶
Create PredictedInstance from numpy array with backward compatibility.
This provides backward compatibility for PredictedInstance.from_numpy() method signature changes. Maps old parameter names to new ones.