Just give the number_of_colors variable a number as big as possible. System will process it properly.

import colorgram as cg

color_list = cg.extract("dot-img.jpg", 2 ** 32)
color_palette = []

for count in range(len(color_list)):
    rgb = color_list[count]
    color = rgb.rgb
    color_palette.append(color)

The source code in colorgram:

def get_colors(samples, used, number_of_colors):
    pixels = 0
    colors = []
    number_of_colors = min(number_of_colors, len(used))

    for count, index in used[:number_of_colors]:
        pixels += count

        color = Color(
            samples[index]     // count,
            samples[index + 1] // count,
            samples[index + 2] // count,
            count
        )

        colors.append(color)
    for color in colors:
        color.proportion /= pixels
    return colors
Answer from BaiJiFeiLong on Stack Overflow
🌐
PyPI
pypi.org › project › colorgram.py
colorgram.py · PyPI
September 16, 2016 - A Python module for extracting colors from images. Get a palette of any picture! ... colorgram.py is a Python library that lets you extract colors from images.
🌐
piwheels
piwheels.org › project › colorgram-py
piwheels - colorgram.py
September 3, 2026 - The piwheels project page for colorgram.py: A Python module for extracting colors from images. Get a palette of any picture!
🌐
GitHub
github.com › mondeique › color-extraction
GitHub - mondeique/color-extraction: color-extraction code by using colorgram.py · GitHub
color-extraction by using colorgram.py · pip install colorgram.py pip install colormap pip install easydev · import colorgram # Extract 6 colors from an image. colors = colorgram.extract('sweet_pic.jpg', 6) # colorgram.extract returns Color objects, which let you access # RGB, HSL, and what proportion of the image was that color.
🌐
YouTube
youtube.com › watch
Extracting RGB values from Image in Python | Colorgram Package | Python for Beginners #lec117 - YouTube
🔥 Master Generative AI from Scratch – GenAI Course for Beginners 🚀 | Start Your AI Career in 2025 🔗 GenAI Course for Beginners Link : https://www.jennysle...
Published: November 7, 2023
🌐
Medium
medium.com › paul-zhao-projects › python-100-projects-in-100-days-learning-journal-333c22a13804
Python 100 projects in 100 days — Learning Journal | by Paul Zhao | Paul Zhao Projects | Medium
November 26, 2020 - Step 1 Extract RGB values from ...append(new_color) print(rgb_colors) We import colorgram, which is a Python library that lets you extract colors from images....
Find elsewhere
🌐
Msav
msav.co.uk › image-analysis-colour-palette-generator
Image Analysis: Colour Palette Generator
There are a few Python 3 packges requried for this tool: pip install colorgram.py - colourgram is a simple module which allows us to get the RGB and HSL values from an image
🌐
GitHub
github.com › obskyr › colorgram.py › blob › master › setup.py
colorgram.py/setup.py at master · obskyr/colorgram.py
A Python module for extracting colors from images. Get a palette of any picture! - obskyr/colorgram.py
Author: obskyr
🌐
Python Mania
pythonmania.org › home › blog › colorgram python library (with matplotlib integration)
Colorgram Python Library (With Matplotlib Integration)
May 16, 2023 - Colorgram is a powerful Python library designed to facilitate color analysis and extraction from images. It allows users to extract...
🌐
Reddit
reddit.com › r/learnpython › need some explanation on how i was able to extract data in a tuple from an object
r/learnpython on Reddit: Need some explanation on how I was able to extract data in a tuple from an object
February 4, 2022 -

I am in the process of learning OOP and tuples. I am using the colorgram.py package to extract RGB color data from a .jpg.

import colorgram

# extract() method takes the arguments of a .jpg and the number of colors to extract
colors = colorgram.extract('hirst_image.jpg', 2)
print(f"A {colors}")

firstColor = colors[0]
rgb = firstColor.rgb
print(f"B {rgb}")

r = rgb[0]
g = rgb[1]
b = rgb[2]

print(f"C {r, g, b}")

My confusion starts with what method colorgram.extract('hirst_image.jpg', 2) returns. print(f"A {colors}") displays

A [<colorgram.py Color: Rgb(r=250, g=249, b=245), 98.03692680376092%>, <colorgram.py Color: Rgb(r=207, g=165, b=127), 1.963073196239071%>]

When I see this I understand it as a list of dictionaries with a key of "Color" that has a value of list which is a tuple Rgb(r=250, g=249, b=245) and a float 98.03692680376092%. I feel like I'm incorrect in my understanding.

The second confusing bit is when I create the variable rgb = firstColor.rgb. When I print(f"B {rgb}") it is displayed as Rgb(r=250, g=249, b=245). As I understand this, I have pulled the tuple from the "Color" dict but I did it in a manner that doesn't make sense to me. Shouldn't I have extracted the tuple Rgb(r=250, g=249, b=245) with key of "Color" instead of firstColor.rgb?

In the end I got the result I was after, which was to pull out individual items from a tuple, I just don't understand how. This is not ok with me.

🌐
YouTube
youtube.com › based_npc
Installing colorgram package into pyCharm - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket · © 2024 Google LLC
Published: April 4, 2023
Views: 898
🌐
Reddit
reddit.com › r/learnpython › problem with importing 'colorgram' module
r/learnpython on Reddit: Problem with importing 'colorgram' module
September 6, 2022 -

So, basically it's more a PyCharm problem than a Python one. I want to use the module 'colorgram' as I mentioned in the title, so I installed it with the package installer of PyCharm. But when I tried to call it with:

"import colorgram"

The program stopped running because of 'ModuleNotFoundError'. I tries using the same method for other modules, but no problem at all. Anybody else got into similar problems?

🌐
Medium
medium.com › @brooklinsantosh › how-to-paint-like-damien-hirst-using-python-c534798dc5a2
How to paint like Damien Hirst using Python | by Brooklin Santosh | Medium
February 17, 2023 - #If you are following the same pattern in working directory use the below code img_path = "images/image.jpg" #Number of colors to extract from the image num_of_colors = 30 #Extarcting colors colors = colorgram.extract(img_path, num_of_colors)
🌐
GitHub
github.com › topics › colorgram
colorgram · GitHub Topics · GitHub
Python Turtle Graphics project that recreates Damien Hirst-inspired dot paintings using Colorgram for RGB palette extraction and random color generation.
🌐
Libraries.io
libraries.io › pypi › colorgram.py
colorgram.py 1.2.0 on PyPI - Libraries.io - security & maintenance data for open source software
color, colors, palette, extract, image, picture, color-extraction, image-processing, pillow, python, python-library ... colorgram.py is a Python library that lets you extract colors from images.
🌐
PyPI
pypi.org › project › colorgram-rs
colorgram-rs · PyPI
colorgram-rs is a package on the Python Package Index (PyPI).