deeplabcut.post_processing.analyze_skeleton
Contributed by Federico Claudi - https://github.com/FedeClaudi
Functions:
| Name | Description |
|---|---|
analyzebone |
Compute length and orientation of the bone at each frame. |
analyzeskeleton |
Extracts length and orientation of each "bone" of the skeleton. |
angle_between_points_2d_anticlockwise |
Determine the angle of a straight line drawn between point one and two. |
calc_angle_between_vectors_of_points_2d |
Calculate the clockwise angle between each set of points for two 2d arrays. |
calc_distance_between_points_two_vectors_2d |
Calculate pairwise distance between vector points. |
analyzebone
Compute length and orientation of the bone at each frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
First body part data. |
required | |
|
Second body part data. |
required |
Source code in deeplabcut/post_processing/analyze_skeleton.py
analyzeskeleton
analyzeskeleton(
config: str | Path,
videos: list[str | Path],
video_extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
filtered=False,
save_as_csv=False,
destfolder=None,
modelprefix="",
track_method="",
return_data=False,
**kwargs
)
Extracts length and orientation of each "bone" of the skeleton.
The bone and skeleton information is defined in the config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Full path of the config.yaml file. |
required |
|
list[str | Path]
|
The full paths to videos for analysis or a path to the directory, where all the videos with same extension are stored. |
required |
|
str | Sequence[str] | None
|
Controls how |
None
|
|
int
|
The shuffle index of training dataset. The extracted frames will be stored in the labeled-dataset for the corresponding shuffle of training dataset. Defaults to 1. |
1
|
|
int
|
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml. Defaults to 0. |
0
|
|
bool
|
Boolean variable indicating if filtered output should
be plotted rather than frame-by-frame predictions. Filtered version can be
calculated with |
False
|
|
bool
|
Saves the predictions in a .csv file. Defaults to False. |
False
|
|
string or None
|
Specifies the destination folder for
analysis data. If |
None
|
|
str
|
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder. Defaults to "". |
''
|
|
string
|
Specifies the tracker used to generate the data. Empty by default (corresponding to a single animal project). For multiple animals, must be either 'box', 'skeleton', or 'ellipse' and will be taken from the config.yaml file if none is given. Defaults to "". |
''
|
|
bool
|
If True, returns a dictionary of the filtered data keyed by video names. Defaults to False. |
False
|
|
Additional arguments. For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary mapping video filepaths to skeleton dataframes.
|
Source code in deeplabcut/post_processing/analyze_skeleton.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
angle_between_points_2d_anticlockwise
Determine the angle of a straight line drawn between point one and two.
The number returned, which is a double in degrees, tells us how much we have to rotate a horizontal line anti-clockwise for it to match the line between the two points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray or list
|
Array or list with the X and Y coordinates of the point. |
required |
|
ndarray or list
|
Array or list with the X and Y coordinates of the point. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
Clockwise angle between p1 and p2 using the inner product and the determinant of the two vectors. |
Examples:
Calculate the clockwise angle between points:
zero = angle_between_points_2d_clockwise([0, 1], [0, 1])
ninety = angle_between_points_2d_clockwise([1, 0], [0, 1])
oneeighty = angle_between_points_2d_clockwise([0, -1], [0, 1])
twoseventy = angle_between_points_2d_clockwise([-1, 0], [0, 1])
ninety2 = angle_between_points_2d_clockwise([10, 0], [10, 1])
print(ninety2)
Source code in deeplabcut/post_processing/analyze_skeleton.py
calc_angle_between_vectors_of_points_2d
Calculate the clockwise angle between each set of points for two 2d arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
2d array with X,Y position at each timepoint. |
required |
|
ndarray
|
2d array with X,Y position at each timepoint. |
required |
Returns:
| Type | Description |
|---|---|
|
np.ndarray: 1d array with clockwise angle between pairwise points in v1,v2. |
Testing
Calculate the clockwise angle:
v1 = np.zeros((2, 4))
v1[1, :] = [
1,
1,
1,
1,
]
v2 = np.zeros((2, 4))
v2[0, :] = [0, 1, 0, -1]
v2[1, :] = [1, 0, -1, 0]
a = calc_angle_between_vectors_of_points_2d(v2, v1)
Source code in deeplabcut/post_processing/analyze_skeleton.py
calc_distance_between_points_two_vectors_2d
Calculate pairwise distance between vector points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
array
|
First array of 2D points. |
required |
|
array
|
Second array of 2D points. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input arguments have invalid data format, shape, or length. |
Returns:
| Name | Type | Description |
|---|---|---|
list |
Pairwise Euclidean distances between corresponding points. |
Examples:
Calculate pairwise Euclidean distances between corresponding points:
v1 = np.zeros((2, 5))
v2 = np.zeros((2, 5))
v2[1, :] = [0, 10, 25, 50, 100]
d = calc_distance_between_points_two_vectors_2d(v1.T, v2.T)