Finding the dominant color of an image is not an easy task. Averaging pixel values turns them to mush. This script simply grabs a random sampling of pixels and reports back the most common rgb color. It's dumb, but it's practical. Some strategies use a color histogram, but more advanced techniques need to consider contrast and focal points in order to provide anything really meaningful. In any case, it's a fun problem to consider and poke at!
dctalbot / dominant-color Goto Github PK
View Code? Open in Web Editor NEWGet common colors in an image using canvas