hyperion-project / hyperion.ng

The successor to Hyperion aka Hyperion Next Generation
https://hyperion-project.org/
MIT License
3.15k stars 389 forks source link

Calculate the "most common" color rather than the average #1382

Closed chcore closed 1 year ago

chcore commented 3 years ago

Feature request

Let's say I have set up my smart bulb to display a color based on the content in the lower-right corner of the screen. The corner contains some red pixels and some blue pixels. My bulb lights up with a purple color, but this color is not in the picture at all. It should display either red or blue, based on which is more prominent or perhaps which is more prominent in the pixels closer to the edge of the screen.

What problem does this feature solve?

More accurate colors for light bulbs.

What does the proposed API look like?

Probably a toggle in the web interface when setting up LEDs

How should this be implemented in your opinion?

I don't know enough C++ to understand how Hyperion currently works, but I would imagine a simple implementation like:

  1. Reduce the number of colors in the relevant part of the image (e.g. if working with RGB, clamp to multiples of 8 or 16 or something)
  2. Find the most common color and note which pixels have that color
  3. Calculate the average of the un-clamped colors of those pixels and send that to the bulb

Are you willing to work on this yourself?

Unfortunately I don't know enough C++, nor am I confident in my ability to code this with an acceptable hit to performance

xkns commented 2 years ago

I have used such dominant color extraction in the past and found that many implementations are based on a javascript implementation called Color Thief. They also have a live web demo.

Sadly I don't currently have the time to try and implement this but I thought I'd at least contribute a possible starting point.