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

Return the percentage the color covers in the image #1

Open
jyotiska opened this issue May 18, 2015 · 6 comments
Open

Return the percentage the color covers in the image #1

jyotiska opened this issue May 18, 2015 · 6 comments

Comments

@jyotiska
Copy link

Hi,

I am playing with this for a last couple of days. Is it possible to return the percentage each color covers in a given image?

@richardcornish
Copy link

I'm also interested in this data. Is there another library that can do it?

@amitmadan18
Copy link

I am also interested in the same data @jyotiska @richardcornish
Please let me know if it's possible

@richardcornish
Copy link

If @jyotiska, @amitmadan18, or anybody else needs this information, I figured it out with the help of an issue at the original color-thief repo.

Change the palette method at line 356 in colorthief.py from:

def palette(self):
    return self.vboxes.map(lambda x: x['color'])

to:

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)))

I simply added additional members to each RGB tuple:

  • The pixel count of each color
  • The total sum of all pixels, which will always be the same
  • The integer percentage of each color

Now palette = color_thief.get_palette(color_count=3) will return something like [(236, 70, 70, 1875, 1000, 18), (4, 4, 252, 625, 1000, 6), (4, 4, 4, 7500, 1000, 75)], giving 18%, 6%, and 75%. Tweak to your liking. Fork the repo to make your change.

@jyotiska
Copy link
Author

Correct. If I remember correctly, I also came up with my own hack something like this to print out the histogram.

@amitmadan18
Copy link

Thanks. Even I had came up with the same solution :)
On 14 Jun 2016 11:34, "Jyotiska Khasnabish" notifications@github.com
wrote:

Correct. If I remember correctly, I also came up with my own hack
something like this to print out the histogram.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AHC3hFI2OnmsJS8iskJNADXIIsJNEbpyks5qLkRWgaJpZM4Eepfi
.

@raoulspronck
Copy link

Is is comming to the main package or do I need to make a fork myself?

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

4 participants