https://github.com/hansalemaos/colorcountcython
This module provides functionality to count unique colors in an image represented as a NumPy array and, optionally, group their coordinates. It includes a Cython-based implementation for improved performance.
https://github.com/hansalemaos/colorcountcython
colors colour colours count cv2 numpy
Last synced: 7 months ago
JSON representation
This module provides functionality to count unique colors in an image represented as a NumPy array and, optionally, group their coordinates. It includes a Cython-based implementation for improved performance.
- Host: GitHub
- URL: https://github.com/hansalemaos/colorcountcython
- Owner: hansalemaos
- License: mit
- Created: 2023-10-28T15:04:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-28T15:04:38.000Z (almost 2 years ago)
- Last Synced: 2025-03-21T20:07:34.992Z (7 months ago)
- Topics: colors, colour, colours, count, cv2, numpy
- Language: Python
- Homepage: https://pypi.org/project/colorcountcython/
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# This module provides functionality to count unique colors in an image represented as a NumPy array and, optionally, group their coordinates.
## Tested against Windows / Python 3.11 / Anaconda
## pip install colorcountcython
```python
This module provides functionality to count unique colors in an image represented as a NumPy array and, optionally, group their coordinates. It includes a Cython-based implementation for improved performance.
Functions:
- colorcount(pic, coords=True, count=True):
Count the unique colors in an image represented as a NumPy array. If `coords` is set to True, it also groups the coordinates of each color.Internal Functions:
- _dummyimport():
Internal function to check the availability of Cython.
- searchallcolors(pic, totallengthpic, width, withcoords, withcount):
Cython function to count colors in an image and, if specified, group their coordinates.Parameters:
- pic (ndarray): The input image represented as a NumPy array.
- coords (bool): If True, the function will return the coordinates of each unique color.
- count (bool): If True, the function will return the count of each unique color.Returns:
A dictionary containing unique color information. If `coords` is True, it includes the coordinates of each color. If `count` is True, it includes the count of each color.Note:
The `colorcount` function takes an image as input and returns a dictionary containing color counts and, if specified, color coordinates. The Cython-based implementation in this module enhances the performance of color counting.Example:
from a_cv_imwrite_imread_plus import open_image_in_cv
from colorcountcython import colorcount
b=open_image_in_cv('c:\\tetetete.png')
d=colorcount(pic=b,coords=True, count=True)
print(d)```