Canvas and painting content¶
The painting as a time series from a canvas video: coverage, colourgram, warm/cool, edge density, composition, palette.
What is on the canvas, and how it grows: the painting as a time series.
A video of a painter contains two moving things: the painter, and the painting. Every other module in the toolbox follows the first. This one follows the second, from a video --- or a crop --- that frames the canvas: it reduces each second to one frame in which the painter's hand has been removed by a temporal median (paint stays, a moving hand does not), and measures that frame.
Per second: painted share (pixels that differ from the first seconds by more than a CIELAB distance), a monotone coverage that ignores the dips occlusion causes (running lower quantile, then cumulative maximum), chromatic share (saturated pixels), the hue histogram whose columns make a colourgram --- the painting's own gram, time across, hue down --- the warm and cool shares of it, edge density as a measure of structural detail, and the composition: where the paint's mass sits, how far its left and right halves mirror each other, and how its edges are oriented. Per minute: the dominant colours, by k-means on the chromatic pixels.
None of this knows what the painting is of. It knows when paint arrived, what colour it was, whether it added detail or covered it, and where on the surface it went, which is what a correlation with the music can use. On the live-painting session this was written for, the palette hardly changed across three takes while edge density rose under a leading pianist and fell under a leading painter; the numbers said so before anyone looked.
The frame the canvas occupies should be fixed. A moving head camera needs rectification first, which is a harder problem and not solved here.
composition ¶
composition(frame_bgr, reference_lab=None, paint_threshold=18.0)
Where the paint sits on a canvas frame, and how its structure is oriented.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_bgr
|
ndarray
|
One canvas frame (BGR, uint8). |
required |
reference_lab
|
ndarray | None
|
The blank canvas in CIELAB (int32); when given, "paint" is what differs from it, otherwise every chromatic or dark pixel counts. |
None
|
paint_threshold
|
float
|
CIELAB distance that counts as paint. Defaults to 18. |
18.0
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
dict
|
|
|
dict
|
mask with its mirror image, 1 = symmetric), |
|
dict
|
|
|
dict
|
|
Source code in musicalgestures/_canvas.py
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 | |
painting_content ¶
painting_content(video, fps_sample=None, reference_s=5.0, width=200, paint_threshold=18.0, chroma_threshold=0.25, hue_bins=36, palette_every_s=60.0, n_colours=5, warm=((0, 60), (330, 360)), cool=((160, 260),))
Measure a canvas video second by second.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video
|
Path to a video framing the canvas (a fixed crop works best). |
required | |
fps_sample
|
float
|
Unused placeholder for API symmetry; one measurement per second is always produced from the median of that second's frames. |
None
|
reference_s
|
float
|
Seconds at the start taken as the blank (or initial) canvas. |
5.0
|
width
|
int
|
Working width in pixels. Defaults to 200. |
200
|
paint_threshold
|
float
|
CIELAB distance from the reference counting as paint. |
18.0
|
chroma_threshold
|
float
|
HSV saturation (0–1) above which a pixel is chromatic. |
0.25
|
hue_bins
|
int
|
Bins of the hue histogram. Defaults to 36 (10° each). |
36
|
palette_every_s
|
float
|
Interval of the dominant-colour palette. Defaults to 60 s. |
60.0
|
n_colours
|
int
|
Colours per palette entry. Defaults to 5. |
5
|
warm, cool
|
Hue ranges in degrees counted as warm and cool. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
|
dict
|
|
|
dict
|
(hue_bins, n) sharing of chromatic pixels per hue, |
|
dict
|
arrays from :func: |
|
dict
|
share), ...]} |
Source code in musicalgestures/_canvas.py
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 166 167 168 169 170 171 | |
colourgram_image ¶
colourgram_image(content, gamma=0.5)
The colourgram as an RGB image (hue down, time across), coloured by hue, bright by share.
Source code in musicalgestures/_canvas.py
174 175 176 177 178 179 180 181 | |
mg_painting ¶
mg_painting(self, reference_s=5.0, width=200, dpi=110, title=None, save_data=True, target_name=None, target_name_data=None, target_name_colourgram=None, overwrite=True)
Measure the painting in this video (the video should frame the canvas) and draw it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_s
|
float
|
Seconds at the start taken as the initial canvas. Defaults to 5. |
5.0
|
width
|
int
|
Working width in pixels. Defaults to 200. |
200
|
dpi
|
int
|
Figure resolution. |
110
|
title
|
str
|
Figure title. |
None
|
save_data
|
bool
|
Write the per-second table as CSV. Defaults to True. |
True
|
target_name
|
str
|
Figure path. Defaults to |
None
|
target_name_data
|
str
|
CSV path. Defaults to |
None
|
target_name_colourgram
|
str
|
Raw colourgram path. Defaults to |
None
|
overwrite
|
bool
|
Overwrite or auto-increment. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgFigure |
MgFigure
|
With the content dict in |
MgFigure
|
the colourgram as |
Source code in musicalgestures/_canvas.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 227 228 229 230 231 232 233 234 235 | |