Posegram¶
Which part of the body moved, and when—and the same question asked on the image's own axes so it can be laid beside a motiongram.

The bundled dancer.avi: one row per landmark, head to foot, coloured by that
landmark's speed. The dance lives in the arm and hand rows; the legs stay dark.
pose_waterfall and the trajectory renders say where the body went, pose_segments how
its limbs were angled, pose_center how its centre moved. None of them answers what a
motiongram answers for pixels: what was moving at 04:12. That is usually the question
an annotator has.
Two views, two frames of reference¶
posegram() puts one landmark per row, ordered head to foot with left and right
adjacent. That ordering is the design, not decoration: MediaPipe emits its 33 landmarks in
model order, which scatters the body—nose, eyes, ears, mouth, then shoulders, elbows,
wrists, then eight hand points, then hips, knees, ankles, feet. Plotted that way an arm is
four rows in three places and the picture says nothing. Ordered anatomically a moving limb
is a contiguous band, and the axis reads head / arms / hands / torso / legs.
posegram_spatial() puts image position on the vertical axis instead, which is what a
x-motiongram does. A body crossing the frame draws the same diagonal in both, so the
two can be read against each other—and where they disagree, either the pixels saw
something the pose model missed or the model invented something the pixels do not support.
weight='speed' is the motiongram's own quantity and the comparable one. weight='presence'
brightens by where the body is regardless of motion, which is a different question: a
dancer standing still has presence and no speed.
Things that will bite¶
Pass frame_size whenever you pass landmarks. MediaPipe estimates landmarks it
cannot see and places them outside the picture—on a real 640×360 extraction the
largest y was 1529, four times the frame height. Inferring the frame from the data
therefore scales the plot by an extrapolation, and squeezes the entire body into the top
quarter while the rest goes black. Without frame_size a high percentile is used, which is
robust but still a guess.
Undetected frames are all-NaN, and differencing across one would invent a large displacement going in and another coming out—two spikes bracketing a gap where nothing happened. Those differences are dropped rather than filled, so an undetected stretch reads as no motion.
Pose is one person. MediaPipe Pose returns a single figure, so on footage with two people it follows whichever it locked onto and does not say which.
The posegram: which part of the body moved, and when.
A motiongram collapses one spatial axis of the image per frame and stacks the result over time. A posegram does the same thing with the body as the frame of reference instead of the image: one row per landmark, one column per frame, brightness for how fast that landmark was moving. Read across for a body part's history; read down for a moment's posture of activity.
It answers what the other pose views do not. pose_waterfall and the trajectory renders
say where the body went, pose_segments how its limbs were angled, pose_center how its
centre moved --- and none of them says what was moving at 04:12, which is the question a
motiongram answers for pixels and the one an annotator usually has.
The row order is the design. MediaPipe emits its 33 landmarks in model order, which scatters the body: nose, eyes, ears, mouth, then shoulders, elbows, wrists, then eight hand points, then hips, knees, ankles, feet. Plotted that way an arm is four rows in three places and the image says nothing. Ordered head to foot it reads as a body, and a moving limb is a contiguous band.
pose_activity ¶
pose_activity(landmarks, anatomical=False, min_visibility=0.0)
Speed of every landmark, per frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
required |
anatomical
|
bool
|
Return the rows in |
False
|
min_visibility
|
float
|
Drop landmarks the model is not this confident
about. This is pose's equivalent of |
0.0
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: |
Notes
Frames where no pose was detected arrive as NaN, and differencing across one would invent a large displacement on the way in and another on the way out. Those differences are dropped rather than filled, so an undetected stretch reads as no motion rather than as two spikes around a gap.
Source code in musicalgestures/_posegram.py
66 67 68 69 70 71 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 | |
mg_posegram ¶
mg_posegram(self, landmarks=None, times=None, colormap='magma', gamma=0.5, max_width=4000, dpi=130, target_name=None, overwrite=True)
Draw the posegram: landmarks head to foot down the page, time across it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
None
|
times
|
array - like
|
Seconds per frame, needed whenever the landmarks were not sampled at the video's own frame rate. Pose is usually extracted at a reduced rate, so this is usually needed. |
None
|
colormap
|
str
|
Defaults to |
'magma'
|
gamma
|
float
|
Applied before colouring so quiet passages stay visible. Defaults to 0.5. |
0.5
|
max_width
|
int
|
Widest the drawn image may be. One column per frame makes a 149-megapixel picture of a long session; columns are pooled by maximum above this, so a brief accent still shows. Defaults to 4000. |
4000
|
dpi
|
int
|
Defaults to 130. |
130
|
target_name
|
str
|
Output path. Defaults to the input name with
|
None
|
overwrite
|
bool
|
Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'musicalgestures.MgFigure'
|
the posegram, with the activity array in |
Source code in musicalgestures/_posegram.py
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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
pose_spatial_gram ¶
pose_spatial_gram(landmarks, height, width, bins=200, axis='vertical', weight='speed', spread=1.0, min_visibility=0.0)
A posegram on the image's own axes, directly comparable with a motiongram.
The landmark-row posegram above says which body part moved. This says at what height something moved, which is what a vertical motiongram says, so the two can be laid on top of each other: a body crossing the frame draws the same diagonal in both, and where they disagree one of them is wrong about the body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
required |
height
|
int
|
Frame height, for scaling y onto the bins. |
required |
width
|
int
|
Frame width, used when |
required |
bins
|
int
|
Rows in the output. Defaults to 200. |
200
|
axis
|
str
|
|
'vertical'
|
weight
|
str
|
|
'speed'
|
spread
|
float
|
Landmarks are points and a motiongram is continuous, so each is smeared over this many bins to make a comparable picture. Defaults to 1.0. |
1.0
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: |
Notes
Landmarks outside the frame, and frames with no pose, contribute nothing rather than being clamped to an edge --- clamping would pile a lost limb onto row 0 and draw a bright line along the top of the plot that no body ever made.
Source code in musicalgestures/_posegram.py
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 | |
mg_posegram_spatial ¶
mg_posegram_spatial(self, landmarks=None, times=None, frame_size=None, axis='vertical', weight='speed', bins=200, colormap='magma', gamma=0.5, max_width=4000, dpi=130, target_name=None, overwrite=True)
The posegram drawn on the image's axes, so it lines up with a motiongram.
posegram() puts one landmark per row, which answers "which body part moved". This
puts image position on the vertical axis instead, which is what a motiongram does,
so a body crossing the frame draws the same diagonal in both and the two can be laid
against each other. Where they disagree, the pixels saw something the pose model did
not, or the other way round.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
None
|
times
|
array - like
|
Seconds per frame. Pose is usually extracted at a reduced rate, so this is usually needed. |
None
|
frame_size
|
tuple
|
|
None
|
axis
|
str
|
|
'vertical'
|
weight
|
str
|
|
'speed'
|
bins
|
int
|
Rows. Defaults to 200. |
200
|
colormap, gamma, max_width, dpi, target_name, overwrite
|
as |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'musicalgestures.MgFigure'
|
the gram, with the array in |
Source code in musicalgestures/_posegram.py
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
pose_spatial_map ¶
pose_spatial_map(landmarks, width, height, bins=(180, 320), weight='speed', smooth=1.5, min_visibility=0.0)
Where the body was in the frame, as an image — the pose answer to a heat map.
The pixel measures give a "where" panel by accumulating their per-pixel quantity over the whole recording: an image of the room with a bright patch where things happened. This is the same kind of object from landmarks, so the four can sit side by side.
Not to be confused with pose_spatial_gram, which has time on one axis. That is a
motiongram-like view and looks, correctly, like a squashed posegram; it answers "at
what height, when", where this answers "where in the room, over the whole recording".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
required |
width, height
|
int
|
The frame the landmarks were extracted in. Not inferred from the data --- MediaPipe places landmarks it cannot see outside the picture, and the maximum is one of those rather than the body. |
required |
bins
|
tuple
|
|
(180, 320)
|
weight
|
str
|
|
'speed'
|
smooth
|
float
|
Gaussian blur in output cells, so 33 points a frame read as a body rather than as confetti. Defaults to 1.5; 0 disables. |
1.5
|
Returns:
| Type | Description |
|---|---|
|
np.ndarray: |
Notes
Landmarks outside the frame contribute nothing rather than being clamped to an edge. Clamping would pile every lost limb onto the border and draw a bright rim that no body ever made.
Source code in musicalgestures/_posegram.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
posegram_arrays ¶
posegram_arrays(landmarks, width, height, bins=200, weight='speed', spread=1.5, min_visibility=0.0)
The horizontal and vertical posegrams, oriented as MGT's motiongrams are.
MGT's two views deliberately run in different directions, so that each shares a spatial axis with the picture and the pair can be laid around the video frame:
- horizontal — a column per frame, tiled left to right. Time runs across, image
y runs down. Shape
(bins, frames). - vertical — a row per frame, tiled top to bottom. Time runs down, image x
runs across. Shape
(frames, bins).
Drawing both with time on the x axis, as an earlier version did, breaks that: the result cannot be placed beside a motiongram of the same recording because its spatial axis no longer lines up with the frame.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in musicalgestures/_posegram.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
mg_posegrams ¶
mg_posegrams(self, landmarks=None, times=None, frame_size=None, bins=200, weight='speed', colormap='magma', gamma=0.5, max_width=4000, dpi=130, target_name=None, overwrite=True)
Posegrams of where the body actually was, in the frame's own coordinates.
The pose counterpart of motiongrams(), and oriented the same way: the horizontal
view has time running across with image y down the page, the vertical view has time
running down with image x across. Laid around a video frame they line up with it, and
laid beside a motiongram of the same recording they can be read against it — a body
crossing the room draws the same diagonal in both.
Because pose gives an actual position rather than a region of changed pixels, these are the true location over time, not an estimate of where change happened.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
landmarks
|
ndarray
|
|
None
|
times
|
array - like
|
Seconds per frame; usually needed, since pose is normally extracted at a reduced rate. |
None
|
frame_size
|
tuple
|
|
None
|
bins
|
int
|
Cells along the spatial axis. Defaults to 200. |
200
|
weight
|
str
|
|
'speed'
|
colormap, gamma, max_width, dpi, target_name, overwrite
|
as elsewhere. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MgList |
'musicalgestures.MgList'
|
the horizontal and vertical posegrams, in that order. |
Source code in musicalgestures/_posegram.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |