bedapisl / fast-colorthief

Selection of most dominant colors in image using Modified Median Cut Quantization
45 stars 1 forks source link

Feature: color count #11

Closed sraeuchle closed 1 year ago

sraeuchle commented 1 year ago

Thank you for that awesome port!

I'm using the colorthief original at the moment with the adjustment, that i've added the pixel count for all colors inside the palette. Is it possible to add it here as well somehow?

This feature would be awesome!

e.g.

palette_dict = color_thief.get_palette_ratio(color_count=6)

palette_dict = {
# (r,g,b), color_count (int) or color_ratio (float)
(219, 171, 125), 2684
(149, 130, 116), 456
(27, 17, 13), 12
}

Heres the sniped I used to make this work in the original python lib:

colorthief.py

...

class CMap(object):
    """Color map"""

    def __init__(self):
        self.vboxes = PQueue(lambda x: x['vbox'].count * x['vbox'].volume)

    @property
    def palette(self):
        return dict((x, y) for x, y in self.vboxes.map(lambda x: (x['color'], x['vbox'].count)))   <---- Read the count of the vbox

best regards

bedapisl commented 1 year ago

Hello, I don't think I will implement this, because it would require a breaking change in the API or some ugly workarounds. Sorry.