get-image-colors
get-image-colors copied to clipboard
How I can to get dominant color for image?
I need to get dominant color for specific image (or color frequency).
For example, Color Thief can do it.
Is it possible with get-image-colors?
Thanks
This library does not provide a way to get the dominant color.
Is there a reason you don't want to use color thief?
I found dominant-color but it has a dependency on ImageMagick, which is not ideal.
Maybe @mattdesl or @hughskennedy know of a good module for this.
Hmm last I checked color thief was basically using the same library underneath (for quantizing).
This lib should sort the results based on color frequency, so typically I just take the first color and assume it's the most dominant (ie: frequent). So it might already be what you want?
Wondering what "dominant" really means. 🤔
@zeke for me it means that the average color of this image is black and blue (not semi-tones of them)

Wondering what "dominant" really means. 🤔
It means: “most important, powerful, or influential.” In other words: of the largest coverage.
This lib should sort the results based on color frequency
Agreed.

But― this might be not a good way to get a dominant color. Reddish area can be quantized (merged) into Red and Orange instead of Red alone, in which case it’ll split the largest area up into two and ends up choosing less-covering color as the dominant. Or reddish and blue-ish area can be quantized into Magenta (unlikely though), and produce undesired results.
get-rgba-palette, which this module depends on, has a function palette.bins, which returns the relative percentage of each color. It would seem possible to use this to sort the colors returned by the bins "amount" value.
https://github.com/mattdesl/get-rgba-palette
That's interesting @ijambro. Do you want to take a shot at that in a pull request?