Frameaverage¶
mg_pixelarray ¶
mg_pixelarray(self, width=640, target_name=None, overwrite=True)
Creates a 'Frame-Averaged Pixel Array' of a video by reducing each frame to a single pixel and arranging all frames into a single image. This is equivalent to the bash script that scales each frame to 1x1 pixel and then tiles them into a grid.
Based on the original bash script concept: - Each frame is reduced to a single pixel (average color of the frame) - All pixel values are arranged in a grid with specified width - Height is calculated automatically based on total frames and width
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the output image in pixels (number of frame-pixels per row). Defaults to 640. |
640
|
target_name
|
str
|
The name of the output image file. If None, uses input filename
with 'framearray |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files or to automatically increment target filenames to avoid overwriting. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
A new MgImage pointing to the output frame-averaged pixel array image file. |
Source code in musicalgestures/_frameaverage.py
7 8 9 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 | |
mg_pixelarray_cv2 ¶
mg_pixelarray_cv2(self, width=640, target_name=None, overwrite=True)
Alternative implementation using OpenCV for more control over the process. Creates a 'Frame-Averaged Pixel Array' by reading each frame, calculating its average color, and arranging these average colors in a grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the output image in pixels. Defaults to 640. |
640
|
target_name
|
str
|
The name of the output image file. Defaults to None. |
None
|
overwrite
|
bool
|
Whether to allow overwriting existing files. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
MgImage |
A new MgImage pointing to the output frame-averaged pixel array image file. |
Source code in musicalgestures/_frameaverage.py
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 | |
mg_pixelarray_stats ¶
mg_pixelarray_stats(self, width=640, include_stats=True)
Creates a frame-averaged pixel array and optionally returns statistics about the video. This function provides additional information similar to the bash script's output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the output image in pixels. Defaults to 640. |
640
|
include_stats
|
bool
|
Whether to return detailed statistics. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary containing the generated MgImage and optional statistics. |
Source code in musicalgestures/_frameaverage.py
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 | |