4 ms·
I'm guessing this is a solved-many-times problem :) Here is my own version of the same thing: http://tylerneylon.com/a/imghist/ http://tylerneylon.com/a/imghis
by tylerneylon 14y ago
I'm guessing this is a solved-many-times problem :) Here is my own version of the same thing:
http://tylerneylon.com/a/imghist/ http://tylerneylon.com/a/imghist/
(and source) https://github.com/tylerneylon/imghist/blob/master/imghist.py https://github.com/tylerneylon/imghist/blob/master/imghist.p...
That also includes color histograms.
Thoughts on actually using this:
* If a human is using the color output, it's fun to weigh the colors by cluster sizes.
* To find human-perspective dominant colors, it helps to throw out very-light/dark pixels.
* Dribbble does a very good job of this - look at any of their individual photo pages.
* For production use, C would be much more appropriate at solving this problem (but python is more fun to use).
Another cool application of color analysis like this:
http://www.vijayp.ca/blog/2012/06/colours-in-movie-posters-since-1914/ http://www.vijayp.ca/blog/2012/06/colours-in-movie-posters-s...
- sratner 14y agoA lot depends on what you are trying to achieve. In my case, for example, I wanted to group images that may have perceptually similar colours either as a dominant component or as an accent (say, a red shirt and a white shirt with red stitching). To expand on your points, based on my own experience: * Rather than using the centroid to represent the cluster, pick a representative peak from the hue histogram. This tends to make things less muddy. * Not only do I throw away extreme S/L values, I aggressively weigh everything by S * (0.5 - |0.5 - L|), so bright, saturated colours dominate. Black and white are usually very thin slivers, and I almost never have grey. * As a last step, I convert to Lab space and merge any colours that are perceptually similar (dE < 5.0). This means that large gradients (like an unevenly lit surface) only occupy one sliver of the pie. Unfortunately, in my current implementation this conflicts with my first point above, so the colours I end up with aren't always in the original image -- something I need to fix. Here's my result for one of your images: https://dl.dropbox.com/s/azl2bag84riugg8/imghist.png https://dl.dropbox.com/s/azl2bag84riugg8/imghist.png, notice how the orange has a disproportionally large weight because it is so saturated.