Use a PIL (Python Image Library) histogram. Loop over the histogram and take the average of pixel color weighed by the pixel count.

Answer from olooney on Stack Overflow
๐ŸŒ
Bitbucket
hhsprings.bitbucket.io โ€บ docs โ€บ programming โ€บ examples โ€บ python โ€บ PIL โ€บ ImageColor.html
ImageColor Module โ€” Pillow (PIL) examples - bitbucket.io
Alternatively, the color values can be given as three percentages (0% to 100%). from PIL import Image, ImageDraw img = Image.new("RGB", (32, 32)) dctx = ImageDraw.Draw(img) dctx.ellipse((8, 8, 16, 16), outline="rgb(10%, 100%, 50%)")
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-pillow-colors-on-an-image
Python Pillow - Colors on an Image - GeeksforGeeks
July 23, 2025 - For example- #ffff00 represents yellow where hue is 0.63, saturation is 1.00, and also the lightness value is 0.50. Here, we will create Images with colors using Image.new() method.
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ data science โ€บ image color extraction with python in 4 steps
Image Color Extraction with Python in 4 Steps | Towards Data Science
May 25, 2022 - The color extraction result from the photo of seawater and coconut trees. Images by the author. ... With all the steps we have done so far, let's combine them to apply to other images easily. The function is for applying to images located in the same folder as the python file.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python_pillow โ€บ python_pillow_colors_on_an_image.htm
Python Pillow - Colors on an Image
For example (255, 0, 0, 255) represents a fully opaque red pixel while (0, 255, 0, 128) represents a semi-transparent green pixel. Let's see an example of creating an image using the Python Pillow with RGBA ...
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ data science โ€บ computer vision 101: working with color images in python
Computer Vision 101: Working with Color Images in Python | Towards Data Science
March 25, 2020 - In this article, we will be working with the image you already saw as the thumbnail, the circle of colorful crayons. It was not accidental that such a colorful picture was selected :) We start by loading the grayscale image into Python and printing it.
๐ŸŒ
GitConnected
levelup.gitconnected.com โ€บ reading-and-analyzing-image-file-data-and-colors-with-python-from-matrices-to-web-applications-d18010f8966f
Pick Colors from Image File Using Python | by Ebo Jackson | Level Up Coding
June 11, 2023 - Each element of the matrix represents ... example, a grayscale image can be represented as a 2D matrix where each element of the matrix is a single integer representing the grayscale value of the corresponding pixel....
๐ŸŒ
Analytics India Magazine
analyticsindiamag.com โ€บ aim โ€บ deep tech โ€บ guide to image color analyzer in python -
Guide To Image Color Analyzer In Python | AIM
July 15, 2024 - Therefore, as the size of tiles increases, the resolution of the image decreases, and the fineness of the tiles increases the resolution of the images. The simplest way to explain the pixels is that they consist of Red, Green, and Blue.
Find elsewhere
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ examples โ€บ color-detection
Color Detection using Python - Beginner's Reference - AskPython
April 19, 2026 - def detect_color_by_rgb(image, target_rgb, threshold=50): output = image.copy() for y in range(image.shape[0]): for x in range(image.shape[1]): b, g, r = output[y, x] distance = np.sqrt((r - target_rgb[0])**2 + (g - target_rgb[1])**2 + (b - ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-pil-imagecolor-getcolor-method
Python PIL | ImageColor.getcolor() Method - GeeksforGeeks
December 12, 2021 - Syntax: PIL.ImageColor.getcolor(color, mode) Parameters: color - A color string Returns: (graylevel [, alpha]) or (red, green, blue[, alpha]) Python3 ยท # importing Image module from PIL package from PIL import Image, ImageColor # using getcolor im = ImageColor.getcolor("orange", "L") print(im) im1 = ImageColor.getcolor("red", "L") print(im1) Output: 173 76 ยท Another Example:- Here used different colors.
๐ŸŒ
HolyPython
holypython.com โ€บ home โ€บ python pil tutorial โ€บ color modes explained for digital image processing in python (pil)
Color Modes Explained for Digital Image Processing in Python (PIL) | HolyPython.com
December 10, 2022 - Here is how the data for each image will look: ... Here is the Python code that can be used to acquire the data above. from PIL import img = Image.new("CMYK", (150,150), color=(255,0,0,0)) img_data = img.getdata() # img.show() img.save("Des...
๐ŸŒ
Medium
medium.com โ€บ data-science โ€บ image-color-identification-with-machine-learning-and-image-processing-using-python-f3dd0606bdca
Image color identification with Machine Learning and Image Processing, using Python | by Piero Paialunga | TDS Archive | Medium
February 14, 2022 - This great article gives us a really good hint. In fact, the main idea is that it is possible to use the image as a (N_rows X N_columns X N_channels) vector. Considering this vector, it is possible to apply the K Means algorithm and identify k clusters, that will be our colors.
๐ŸŒ
Medium
medium.com โ€บ data-science โ€บ image-color-extraction-with-python-in-4-steps-8d9370d9216e
Image Color Extraction with Python in 4 Steps | by Boriharn K | TDS Archive | Medium
June 3, 2022 - Images by the author. If the outcome has no color you are looking for, there are two methods to help get the color. ... For example, I will exact the pink color of a hibiscus flower, a tropical flower, in the center of the photo below.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-get-the-list-of-colors-in-an-image-in-python
How to get the list of colors in an image in Python
There are many modules in the PIL library for different purposes. One such module is the Image module. The Image module offers a variety of factory operations, including tools for generating new pictures and loading images from files. The getcolors() function is used to get a list of colors present in the image.
๐ŸŒ
Omz Software
omz-software.com โ€บ pythonista โ€บ docs โ€บ ios โ€บ ImageColor.html
The ImageColor Module โ€” Python 3.6.1 documentation
The ImageColor module supports the following string formats: Hexadecimal color specifiers, given as โ€œ#rgbโ€ or โ€œ#rrggbbโ€. For example, โ€œ#ff0000โ€ specifies pure red.
๐ŸŒ
DEV Community
dev.to โ€บ codesphere โ€บ visualizing-the-color-spaces-of-images-with-python-and-matplotlib-1nmk
Visualizing the Color Spaces of Images with Python and MatPlotLib - DEV Community
May 27, 2022 - In our example, the red value of a color determines its x coordinate, green determines its y coordinate, and blue determines its z coordinate. As you can see, when x and z are both 255 then we get violet, and when all 3 color parameters are ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ find-most-used-colors-in-image-using-python
Find most used colors in image using Python | GeeksforGeeks
October 16, 2021 - Not only supported by any system, such as Windows, Linux, Mac, etc. but also it can be run in any programming language like Python, C++, Java, etc. OpenCV also allows you to identify color in images.
๐ŸŒ
Pillow Documentation
pillow.readthedocs.io โ€บ en โ€บ stable โ€บ reference โ€บ ImageColor.html
ImageColor module - Pillow (PIL Fork) 13.0.0 documentation
The ImageColor module supports ... and a is alpha (also called โ€˜opacityโ€™). For example, #ff0000 specifies pure red, and #ff0000cc specifies red with 80% opacity (cc is 204 in decimal form, and 204 / 255 = 0.8)...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ color-identification-in-images-using-python-opencv
Color Identification in Images using Python - OpenCV - GeeksforGeeks
January 3, 2023 - For finding the specified color in the given image, we need to use the lower and upper bound of that color. Example: For finding the green color in the image, we need to specify the lower and upper HSV color code for green color as follows.