get-image-colors icon indicating copy to clipboard operation
get-image-colors copied to clipboard

How I can to get dominant color for image?

Open indapublic opened this issue 8 years ago • 9 comments

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

indapublic avatar Apr 08 '17 13:04 indapublic

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.

zeke avatar May 03 '17 19:05 zeke

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?

mattdesl avatar May 03 '17 23:05 mattdesl

Wondering what "dominant" really means. 🤔

zeke avatar May 04 '17 03:05 zeke

@zeke for me it means that the average color of this image is black and blue (not semi-tones of them)

image

idoo avatar Aug 13 '19 08:08 idoo

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.

issuefiler avatar Jan 10 '20 21:01 issuefiler

domcolor

issuefiler avatar Jan 10 '20 21:01 issuefiler

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.

issuefiler avatar Jan 10 '20 21:01 issuefiler

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

ijambro avatar Mar 29 '20 04:03 ijambro

That's interesting @ijambro. Do you want to take a shot at that in a pull request?

zeke avatar Mar 29 '20 16:03 zeke