Spacetime¶
Space-time visualisations of a person in a video: stroboscope (chronophotography), silhouette waterfall, motion history image (MHI), and a 3D space-time silhouette volume.
Silhouettes are extracted with MediaPipe selfie segmentation when available, falling back to background subtraction against the average frame (good for static-camera recordings).
mg_stroboscope ¶
mg_stroboscope(self, n_samples=12, method='auto', threshold=0.1, kernel_size=5, keep_largest=False, colorize=True, background='average', target_name=None, overwrite=True)
Deprecated since 1.23.0: use multishot(), which absorbed this.
The two were the same picture made two ways, and having both meant a reader had to
know which. multishot() now carries both: select='even' is this method's regular
sampling, background='average' is its mean-average ground, and colorize=True
is its time tint. The defaults differ because the defaults are an opinion --- moments
chosen for spatial separation, on a median plate --- and even sampling onto a mean
average is what makes two bodies land in the same place on a ground that keeps a ghost
of everyone who crossed.
This wrapper delegates and will be removed at 2.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Silhouettes to composite. Defaults to 12. |
12
|
method
|
str
|
'auto', 'mediapipe' or 'bgsub'. Defaults to 'auto'. |
'auto'
|
threshold
|
float
|
Foreground threshold (0-1). Defaults to 0.1. |
0.1
|
kernel_size
|
int
|
Unused by the replacement; accepted for compatibility. |
5
|
keep_largest
|
bool
|
Unused by the replacement; accepted for compatibility. |
False
|
colorize
|
bool
|
Tint each silhouette by time. Defaults to True. |
True
|
background
|
str
|
'average', 'first', 'black' or 'white'. Defaults to 'average'. |
'average'
|
target_name
|
str
|
Output name. Defaults to "_stroboscope.png". |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
the composite. |
Source code in musicalgestures/_spacetime.py
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 | |
mg_silhouette_waterfall ¶
mg_silhouette_waterfall(self, n_samples=40, method='auto', threshold=0.1, kernel_size=5, keep_largest=False, axis='horizontal', cmap='viridis', dpi=200, elev=35, azim=-60, axes=True, crop=False, target_name=None, overwrite=True)
Renders a 3D silhouette waterfall: the per-frame silhouette projected onto one spatial axis and stacked as cascading curves along a time (depth) axis, so the body's occupancy profile "flows" through time — like a 3D spectrogram waterfall.
For a single person on a static background, raise threshold and/or set
keep_largest=True for a cleaner profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Number of time slices (profiles) to stack. Defaults to 40. |
40
|
method
|
str
|
Silhouette extraction: 'auto', 'mediapipe', or 'bgsub'. Defaults to 'auto'. |
'auto'
|
threshold
|
float
|
Foreground threshold (0–1). Higher rejects more background. Defaults to 0.1. |
0.1
|
kernel_size
|
int
|
Morphological cleanup kernel (0 disables). Defaults to 5. |
5
|
keep_largest
|
bool
|
Keep only the largest blob (the person). Defaults to False. |
False
|
axis
|
str
|
'horizontal' profiles over x (collapse y); 'vertical' profiles over y. Defaults to 'horizontal'. |
'horizontal'
|
cmap
|
str
|
Matplotlib colormap (by time). Defaults to 'viridis'. |
'viridis'
|
dpi
|
int
|
Output DPI. Defaults to 200. |
200
|
elev
|
float
|
3D elevation angle. Defaults to 35. |
35
|
azim
|
float
|
3D azimuth angle. Defaults to -60. |
-60
|
axes
|
bool
|
Draw the axes, tick labels, and title. Set to False for a clean render with all axes and text removed. Defaults to True. |
True
|
crop
|
bool
|
Tighten the spatial axis to the occupied (nonzero) extent and trim the surrounding whitespace, so the figure shows mostly the data. Defaults to False. |
False
|
target_name
|
str
|
Output name. Defaults to None ("_silhouette_waterfall.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the 3D waterfall figure (the stacked profiles are in |
Source code in musicalgestures/_spacetime.py
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 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 | |
mg_motionhistory ¶
mg_motionhistory(self, threshold=0.05, decay=0.3, normalize=False, blur=0, cmap='hot', dpi=300, target_name=None, overwrite=True)
Renders a Motion History Image (Bobick & Davis): a single image where intensity encodes how recently motion occurred at each pixel (recent motion bright, older motion fades out).
A motion mark is set to full intensity where motion occurs and then decays linearly to
zero over a window set by decay, so old motion disappears instead of accumulating and
washing out the image. Raise threshold to ignore background noise, and lower decay
for shorter (less crowded) trails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Motion threshold (0–1) on frame differences. Higher rejects more background noise. Defaults to 0.05. |
0.05
|
decay
|
float
|
Fade window as a fraction of the clip length (0–1): a motion mark fully fades after this fraction of the video. Smaller = shorter trails, less blow-out. Defaults to 0.3. |
0.3
|
normalize
|
bool
|
Stretch the result to the full intensity range. Defaults to False. The MHI is already built in [0, 1], so normalization is rarely needed; when the final frames are static it amplifies faint residual trails and over-brightens ("blows up") the image, so it is guarded to skip when the peak intensity is very low. |
False
|
blur
|
int
|
Optional Gaussian smoothing radius for the difference mask (0 = off). Helps suppress speckle noise. Defaults to 0. |
0
|
cmap
|
str
|
Matplotlib colormap. Defaults to 'hot'. |
'hot'
|
dpi
|
int
|
Output DPI. Defaults to 300. |
300
|
target_name
|
str
|
Output name. Defaults to None ("_mhi.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
the motion history image. |
Source code in musicalgestures/_spacetime.py
344 345 346 347 348 349 350 351 352 353 354 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 419 420 | |
mg_spacetime_volume ¶
mg_spacetime_volume(self, n_samples=50, downsample=8, method='auto', threshold=0.1, kernel_size=5, keep_largest=False, cmap='viridis', dpi=200, elev=20, azim=-60, target_name=None, overwrite=True)
Renders a 3D space-time scatter of the person's silhouette: points (x, y, t) where the silhouette is present, with time on the depth axis and colour, showing how the body occupies space through time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Number of time samples (depth slices). Defaults to 50. |
50
|
downsample
|
int
|
Spatial downsampling factor for the silhouette points. Defaults to 8. |
8
|
method
|
str
|
Silhouette extraction: 'auto', 'mediapipe', or 'bgsub'. Defaults to 'auto'. |
'auto'
|
threshold
|
float
|
Foreground threshold (0–1). Higher rejects more background. Defaults to 0.1. |
0.1
|
kernel_size
|
int
|
Morphological cleanup kernel for the silhouette (0 disables). Defaults to 5. |
5
|
keep_largest
|
bool
|
Keep only the largest blob (the person). Defaults to False. |
False
|
cmap
|
str
|
Matplotlib colormap for time. Defaults to 'viridis'. |
'viridis'
|
dpi
|
int
|
Output DPI. Defaults to 200. |
200
|
elev
|
float
|
3D elevation angle. Defaults to 20. |
20
|
azim
|
float
|
3D azimuth angle. Defaults to -60. |
-60
|
target_name
|
str
|
Output name. Defaults to None ("_spacetime_volume.png"). |
None
|
overwrite
|
bool
|
Overwrite or auto-increment the filename. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
'MgFigure'
|
the 3D space-time figure (data holds the point cloud). |
Source code in musicalgestures/_spacetime.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 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 | |