Having trouble with the Colorgram library in Python

Viewed 17

I am using Python's colorgram library to extract color information from an image. One version of my code is as follows:

import colorgram

num_cols = 25

rgb_colors = []
colors = colorgram.extract('image.jpg', num_cols)
for color in colors:
    r = color.rgb.r
    g = color.rgb.g
    b = color.rgb.b
    new_color = (r, g, b)
    rgb_colors.append(new_color)

print(rgb_colors)
print(len(rgb_colors))

The code works just fine, but if I give 'num_cols' a value of more than 36, the code only finds a maximum of 36 colors. I have tried different hi res images, and have tried different versions of the same code that I found online, but I always get this same limit of 36 colors; I just don't know where the problem can be, and I have not seen anyone else report the same issue. Can someone please tell me if I am doing something stupid here? Thanks.

1 Answers

I know it's not the answer you need, but I just tried you code and it has the same limitation. The most I get from an image is 40. So I don't think it's about your code. It may be a limitation of the colorgram library, but I don't know enough to prove it or discard it. If I find some spare time I'll try other similar libraries and edit my post. Hope you get a complete answer/solution, as I'll probably need it too.

Related