Heatmap¶
mg_heatmap ¶
mg_heatmap(self, colormap='inferno', overlay=True, alpha=0.75, background_dim=0.4, blur=0, normalize=True, gamma=0.5, target_name=None, overwrite=True)
Renders a motion heatmap showing which parts of the video change the most.
The function accumulates the absolute pixel difference between consecutive frames
over the whole video, producing a single image where bright/hot regions mark areas
of frequent or large change and dark/cool regions mark areas that stay still. When
overlay is True the heat is composited on top of a dimmed average frame, so the
activity is shown in the spatial context of the scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colormap
|
str
|
Any matplotlib colormap name used to colour the heat (e.g. 'inferno', 'jet', 'viridis', 'hot', 'magma'). Defaults to 'inferno'. |
'inferno'
|
overlay
|
bool
|
If True, composite the heatmap over a dimmed grayscale average frame so the motion is shown in context. If False, render the bare heatmap on a black background. Defaults to True. |
True
|
alpha
|
float
|
Maximum opacity of the heat overlay in [0, 1]. Hotter
pixels are more opaque. Only used when |
0.75
|
background_dim
|
float
|
Brightness multiplier for the average-frame
background in [0, 1]. Lower values make the heat stand out more. Only used
when |
0.4
|
blur
|
int
|
Radius of an optional Gaussian smoothing applied to the accumulated motion (0 disables). Gives a smoother, less speckled heatmap. Defaults to 0. |
0
|
normalize
|
bool
|
If True, scale the accumulated motion so the most active pixel maps to the top of the colormap. Defaults to True. |
True
|
gamma
|
float
|
Gamma applied to the normalised heat before colouring. Values < 1 boost faint motion so subtle activity is visible; 1.0 is linear. Defaults to 0.5. |
0.5
|
target_name
|
str
|
The name of the output image. Defaults to None (which uses the input filename with the suffix "_heatmap.png"). |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment the target filename to avoid overwriting. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
'MgImage'
|
A new MgImage pointing to the output heatmap image file. |
Source code in musicalgestures/_heatmap.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 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 | |