Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dominant color not working properly #17

Open
Britman72 opened this issue Jan 30, 2020 · 1 comment
Open

Dominant color not working properly #17

Britman72 opened this issue Jan 30, 2020 · 1 comment

Comments

@Britman72
Copy link

Take the following image: https://ibb.co/R3dnBpz

Calling using: dominant_color = color_thief.get_color(quality=1)
The dominant color is clearly yellow (244, 237, 12) but it returns (28, 51, 49).

@Mayvis
Copy link

Mayvis commented Feb 5, 2020

You should see the doc that get_color function mentioned, the bigger the number, the faster a color will be returned but the greater the likelihood that it will not be the visually most dominant color.

So the best way to get dominant color is to change class CMap's palette function in colorthief.py like below

def palette(self):
        total = sum(self.vboxes.map(lambda x: x['vbox'].count))
        return self.vboxes.map(
            lambda x: x['color'] + (x['vbox'].count, total, int(x['vbox'].count / float(total) * 100)))

And use it like below

from colorthief import ColorThief

color_thief = ColorThief('./assets/image/image3.png')  # change to your image path
palette = color_thief.get_palette(color_count=6)
dominant_color = max(palette, key=lambda i: i[-1])[0:3]  # (r, g, b)

print(dominant_color) 
print(palette)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants