Skip to main content

Counts the unique colors in an image and returns a DataFrame with color counts and optional color coordinates.

Project description

Counts the unique colors in an image and returns a DataFrame with color counts and optional color coordinates.

Tested against Windows 10 / Python 3.11 / Anaconda

pip install farbencounter

# Example usage
from farbencounter import count_colors
pic = r"https://www.python.org/static/img/python-logo.png"
img = open_image_in_cv(pic, channels_in_output=3)
df, colorcoords = count_colors(img=img, sort=True, get_color_coords=True)

# df: DataFrame containing color information and counts
# colorcoords: Dictionary containing color coordinates


# df
# Out[3]:
#             a    r    g    b      c
# 0           0    0    0    0    456
# 1          26    0    0   26      2
# 2        3612    0   14   28      2
# 3        3619    0   14   35      1
# 4        3870    0   15   30      9
# ..        ...  ...  ...  ...    ...
# 849  16776316  255  252  124      2
# 850  16776431  255  252  239      1
# 851  16776432  255  252  240      1
# 852  16776830  255  254  126      1
# 853  16777215  255  255  255  18608
# [854 rows x 5 columns]


# colorcoords
# ....
# (44, 99, 147): array([[48, 32]]),
#  (45,
#   45,
#   45): array([[230,  28],
#         [170,  32],
#         [189,  52]], dtype=int64),
#  (45, 86, 119): array([[12, 25]]),
#  (45, 94, 133): array([[ 8, 30]]),
#  (45, 96, 139): array([[20, 43]]),
#  (45, 101, 150): array([[45, 36]]),
#  (46, 35, 12): array([[36, 53]]),
#  (46,
#   46,
#   46): array([[239,  14],
#         [143,  23],
#         [143,  28],
#         [170,  34],
#         [185,  34],
#         [ 84,  45],
#         [ 90,  48],
#         [118,  48],
#         [119,  48],
#         [201,  48],
#         [194,  52]], dtype=int64)
# ....

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

farbencounter-0.10.tar.gz (22.2 kB view hashes)

Uploaded Source

Built Distribution

farbencounter-0.10-py3-none-any.whl (22.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page