Skip to content

Commit 70fe77c

Browse files
committed
Support for dominant color processing on a full image which is applied to all LEDs (#1853)
1 parent d5664b6 commit 70fe77c

File tree

6 files changed

+131
-21
lines changed

6 files changed

+131
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Support for Skydimo devices
1919
- Support gaps on Matrix Layout (#1696)
2020
- Support a configurable grabber inactive detection time interval (#1740)
21+
- Support for dominant color processing on a full image which is applied to all LEDs (#1853)
2122
- Windows: Added a new grabber that uses the DXGI DDA (Desktop Duplication API). This has much better performance than the DX grabber as it does more of its work on the GPU.
2223
- Support to freely select source and target instances to be used by forwarder
2324
- Support to import, export and backup Hyperion's full configuration via the UI, JSON-API and commandline (`--importConfig, --exportConfig`) (#804)

assets/webconfig/i18n/en.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@
407407
"edt_conf_enum_dl_verbose2": "Verbosity level 2",
408408
"edt_conf_enum_dl_verbose3": "Verbosity level 3",
409409
"edt_conf_enum_dominant_color": "Dominant Color - per LED",
410-
"edt_conf_enum_dominant_color_advanced": "Dominant Color Advanced - per LED",
410+
"edt_conf_enum_dominant_color_advanced": "Dominant Color (advanced) - per LED",
411411
"edt_conf_enum_effect": "Effect",
412412
"edt_conf_enum_gbr": "GBR",
413413
"edt_conf_enum_grb": "GRB",
@@ -432,7 +432,9 @@
432432
"edt_conf_enum_transeffect_sudden": "Sudden",
433433
"edt_conf_enum_udp_ddp": "DDP",
434434
"edt_conf_enum_udp_raw": "RAW",
435-
"edt_conf_enum_unicolor_mean": "Mean Color Image - applied to all LEDs",
435+
"edt_conf_enum_unicolor_mean": "Image's mean color - applied to all LEDs",
436+
"edt_conf_enum_unicolor_dominant": "Image's dominant color - applied to all LEDs",
437+
"edt_conf_enum_unicolor_dominant_advanced": "Image's dominant color (advanced) - applied to all LEDs",
436438
"edt_conf_flatbufServer_heading_title": "Flatbuffer Server",
437439
"edt_conf_flatbufServer_timeout_expl": "If no data is received for the given period, the component will be (soft) disabled.",
438440
"edt_conf_flatbufServer_timeout_title": "Timeout",

include/hyperion/ImageProcessor.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,19 @@ public slots:
141141
colors = _imageToLedColors->getUniLedColor(image);
142142
break;
143143
case 2:
144-
colors = _imageToLedColors->getMeanLedColorSqrt(image);
144+
colors = _imageToLedColors->getMeanSqrtLedColor(image);
145145
break;
146146
case 3:
147147
colors = _imageToLedColors->getDominantLedColor(image);
148148
break;
149149
case 4:
150-
colors = _imageToLedColors->getDominantLedColorAdv(image);
150+
colors = _imageToLedColors->getDominantUniLedColor(image);
151+
break;
152+
case 5:
153+
colors = _imageToLedColors->getDominantAdvLedColor(image);
154+
break;
155+
case 6:
156+
colors = _imageToLedColors->getDominantAdvUniLedColor(image);
151157
break;
152158
default:
153159
colors = _imageToLedColors->getMeanLedColor(image);
@@ -186,14 +192,21 @@ public slots:
186192
_imageToLedColors->getUniLedColor(image, ledColors);
187193
break;
188194
case 2:
189-
_imageToLedColors->getMeanLedColorSqrt(image, ledColors);
195+
_imageToLedColors->getMeanSqrtLedColor(image, ledColors);
190196
break;
191197
case 3:
192198
_imageToLedColors->getDominantLedColor(image, ledColors);
193199
break;
194200
case 4:
195-
_imageToLedColors->getDominantLedColorAdv(image, ledColors);
201+
_imageToLedColors->getDominantUniLedColor(image, ledColors);
202+
break;
203+
case 5:
204+
_imageToLedColors->getDominantAdvLedColor(image, ledColors);
196205
break;
206+
case 6:
207+
_imageToLedColors->getDominantAdvUniLedColor(image, ledColors);
208+
break;
209+
197210
default:
198211
_imageToLedColors->getMeanLedColor(image, ledColors);
199212
}

include/hyperion/ImageToLedsMap.h

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ namespace hyperion
128128
/// @return The vector containing the output
129129
///
130130
template <typename Pixel_T>
131-
std::vector<ColorRgb> getMeanLedColorSqrt(const Image<Pixel_T> & image) const
131+
std::vector<ColorRgb> getMeanSqrtLedColor(const Image<Pixel_T> & image) const
132132
{
133133
std::vector<ColorRgb> colors(_colorsMap.size(), ColorRgb{0,0,0});
134-
getMeanLedColorSqrt(image, colors);
134+
getMeanSqrtLedColor(image, colors);
135135
return colors;
136136
}
137137

@@ -143,7 +143,7 @@ namespace hyperion
143143
/// @param[out] ledColors The vector containing the output
144144
///
145145
template <typename Pixel_T>
146-
void getMeanLedColorSqrt(const Image<Pixel_T> & image, std::vector<ColorRgb> & ledColors) const
146+
void getMeanSqrtLedColor(const Image<Pixel_T> & image, std::vector<ColorRgb> & ledColors) const
147147
{
148148
if(_colorsMap.size() != ledColors.size())
149149
{
@@ -239,18 +239,54 @@ namespace hyperion
239239
}
240240

241241
///
242-
/// Determines the dominant color using a k-means algorithm for each LED using the LED area mapping given
242+
/// Determines the dominant color of the image and assigns it to all LEDs
243+
///
244+
/// @param[in] image The image from which to extract the led color
245+
///
246+
/// @return The vector containing the output
247+
///
248+
template <typename Pixel_T>
249+
std::vector<ColorRgb> getDominantUniLedColor(const Image<Pixel_T> & image) const
250+
{
251+
std::vector<ColorRgb> colors(_colorsMap.size(), ColorRgb{0,0,0});
252+
getDominantUniLedColor(image, colors);
253+
return colors;
254+
}
255+
256+
///
257+
/// Determines the dominant color of the image and assigns it to all LEDs
258+
///
259+
/// @param[in] image The image from which to extract the LED colors
260+
/// @param[out] ledColors The vector containing the output
261+
///
262+
template <typename Pixel_T>
263+
void getDominantUniLedColor(const Image<Pixel_T> & image, std::vector<ColorRgb> & ledColors) const
264+
{
265+
if(_colorsMap.size() != ledColors.size())
266+
{
267+
Debug(_log, "ImageToLedsMap: colorsMap.size != ledColors.size -> %d != %d", _colorsMap.size(), ledColors.size());
268+
return;
269+
}
270+
271+
// calculate dominant color
272+
const ColorRgb color = calculateDominantColor(image);
273+
//Update all LEDs with same color
274+
std::fill(ledColors.begin(),ledColors.end(), color);
275+
}
276+
277+
///
278+
/// Determines the dominant color using a k-means algorithm for each LED using the LED area mapping given
243279
/// at construction.
244280
///
245281
/// @param[in] image The image from which to extract the LED color
246282
///
247283
/// @return The vector containing the output
248284
///
249285
template <typename Pixel_T>
250-
std::vector<ColorRgb> getDominantLedColorAdv(const Image<Pixel_T> & image) const
286+
std::vector<ColorRgb> getDominantAdvLedColor(const Image<Pixel_T> & image) const
251287
{
252288
std::vector<ColorRgb> colors(_colorsMap.size(), ColorRgb{0,0,0});
253-
getDominantLedColorAdv(image, colors);
289+
getDominantAdvLedColor(image, colors);
254290
return colors;
255291
}
256292

@@ -262,7 +298,7 @@ namespace hyperion
262298
/// @param[out] ledColors The vector containing the output
263299
///
264300
template <typename Pixel_T>
265-
void getDominantLedColorAdv(const Image<Pixel_T> & image, std::vector<ColorRgb> & ledColors) const
301+
void getDominantAdvLedColor(const Image<Pixel_T> & image, std::vector<ColorRgb> & ledColors) const
266302
{
267303
// Sanity check for the number of LEDs
268304
if(_colorsMap.size() != ledColors.size())
@@ -280,6 +316,42 @@ namespace hyperion
280316
}
281317
}
282318

319+
///
320+
/// Determines the dominant color of the image using a k-means algorithm and assigns it to all LEDs
321+
///
322+
/// @param[in] image The image from which to extract the led color
323+
///
324+
/// @return The vector containing the output
325+
///
326+
template <typename Pixel_T>
327+
std::vector<ColorRgb> getDominantAdvUniLedColor(const Image<Pixel_T> & image) const
328+
{
329+
std::vector<ColorRgb> colors(_colorsMap.size(), ColorRgb{0,0,0});
330+
getDominantAdvUniLedColor(image, colors);
331+
return colors;
332+
}
333+
334+
///
335+
/// Determines the dominant color of the image using a k-means algorithm and assigns it to all LEDs
336+
///
337+
/// @param[in] image The image from which to extract the LED colors
338+
/// @param[out] ledColors The vector containing the output
339+
///
340+
template <typename Pixel_T>
341+
void getDominantAdvUniLedColor(const Image<Pixel_T> & image, std::vector<ColorRgb> & ledColors) const
342+
{
343+
if(_colorsMap.size() != ledColors.size())
344+
{
345+
Debug(_log, "ImageToLedsMap: colorsMap.size != ledColors.size -> %d != %d", _colorsMap.size(), ledColors.size());
346+
return;
347+
}
348+
349+
// calculate dominant color
350+
const ColorRgb color = calculateDominantColorAdv(image);
351+
//Update all LEDs with same color
352+
std::fill(ledColors.begin(),ledColors.end(), color);
353+
}
354+
283355
private:
284356

285357
Logger* _log;

libsrc/hyperion/ImageProcessor.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,63 @@ void ImageProcessor::registerProcessingUnit(
4040
// global transform method
4141
int ImageProcessor::mappingTypeToInt(const QString& mappingType)
4242
{
43-
if (mappingType == "unicolor_mean" )
43+
if (mappingType == "multicolor_mean" )
4444
{
45-
return 1;
45+
return 0;
4646
}
4747
else if (mappingType == "multicolor_mean_squared" )
48+
{
49+
return 1;
50+
}
51+
else if (mappingType == "unicolor_mean" )
4852
{
4953
return 2;
5054
}
5155
else if (mappingType == "dominant_color" )
5256
{
5357
return 3;
5458
}
55-
else if (mappingType == "dominant_color_advanced" )
59+
else if (mappingType == "unicolor_dominant" )
5660
{
5761
return 4;
5862
}
63+
else if (mappingType == "dominant_color_advanced" )
64+
{
65+
return 5;
66+
}
67+
else if (mappingType == "unicolor_dominant_advanced" )
68+
{
69+
return 6;
70+
}
5971
return 0;
6072
}
6173
// global transform method
6274
QString ImageProcessor::mappingTypeToStr(int mappingType)
6375
{
6476
QString typeText;
6577
switch (mappingType) {
78+
79+
case 0:
80+
typeText = "multicolor_mean";
81+
break;
6682
case 1:
67-
typeText = "unicolor_mean";
83+
typeText = "multicolor_mean_squared";
6884
break;
6985
case 2:
70-
typeText = "multicolor_mean_squared";
86+
typeText = "unicolor_mean";
7187
break;
7288
case 3:
7389
typeText = "dominant_color";
7490
break;
7591
case 4:
92+
typeText = "unicolor_dominant";
93+
break;
94+
case 5:
7695
typeText = "dominant_color_advanced";
7796
break;
97+
case 6:
98+
typeText = "unicolor_dominant_advanced";
99+
break;
78100
default:
79101
typeText = "multicolor_mean";
80102
break;

libsrc/hyperion/schema/schema-color.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"type" : "string",
99
"required" : true,
1010
"title" : "edt_conf_color_imageToLedMappingType_title",
11-
"enum" : ["multicolor_mean", "unicolor_mean", "multicolor_mean_squared", "dominant_color", "dominant_color_advanced"],
11+
"enum" : ["multicolor_mean","multicolor_mean_squared", "unicolor_mean", "dominant_color", "unicolor_dominant", "dominant_color_advanced", "unicolor_dominant_advanced"],
1212
"default" : "multicolor_mean",
1313
"options" : {
14-
"enum_titles" : ["edt_conf_enum_multicolor_mean", "edt_conf_enum_unicolor_mean", "edt_conf_enum_multicolor_mean_squared", "edt_conf_enum_dominant_color", "edt_conf_enum_dominant_color_advanced"]
14+
"enum_titles" : ["edt_conf_enum_multicolor_mean","edt_conf_enum_multicolor_mean_squared", "edt_conf_enum_unicolor_mean", "edt_conf_enum_dominant_color", "edt_conf_enum_unicolor_dominant", "edt_conf_enum_dominant_color_advanced", "edt_conf_enum_unicolor_dominant_advanced"]
1515
},
1616
"propertyOrder" : 1
1717
},
@@ -24,7 +24,7 @@
2424
"propertyOrder": 2,
2525
"options": {
2626
"dependencies": {
27-
"imageToLedMappingType": "dominant_color_advanced"
27+
"imageToLedMappingType": ["dominant_color_advanced", "unicolor_dominant_advanced"]
2828
}
2929
}
3030
},

0 commit comments

Comments
 (0)