ImageDominantColor
Get the dominant color of any image
Introduction
ImageDominantColor is a Python package/library for detecting dominant color of images.
It can take any input image and tell the dominant color in image. It does not uses k-means clustering for detecting dominant color but instead quantize the individual pixels and calculates the statistical mode of the quantized values. And yes, it works!
ImageDominantColor does not depend on numpy unlike most of the other implementations for the same task and is also fast and minimalist.
What ImageDominantColor is not?
ImageDominantColor does not calculates the average color of the image. Also note that the average color of an image is not same as its dominant color.
Installation
- Using pip:
pip install imagedominantcolor -U
- Install directly from GitHub:
pip install git+https://github.com/akamhy/imagedominantcolor.git
Usage
>>> from imagedominantcolor import DominantColor
>>> file_path = "blue_butterfly.jpg" # Blue color is dominant
>>> dominantcolor = DominantColor(file_path)
>>> dominantcolor.dominant_color
'b'
>>> dominantcolor.rgb
(3, 6, 244)
>>> dir(dominantcolor)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'b', 'counter', 'dominant_color', 'dominant_color_of_pixel', 'dominant_color_of_pixels_of_image_array', 'g', 'generate_dominant_color_of_pixels_of_image_array', 'image', 'image_data', 'image_path', 'l', 'minimum_percent_difference_of_rgb', 'mpd', 'r', 'resize_value', 'resized_image', 'rgb', 'rgbl', 'set_dominat_color_of_image', 'set_rgbl_value_of_image', 'total_pixels']
>>> dominantcolor.total_pixels
256
>>> dominantcolor.r
3
>>> dominantcolor.g
6
>>> dominantcolor.b
244
>>> dominantcolor.l
3
>>> dominantcolor.rgbl
(3, 6, 244, 3)
>>> repr(dominantcolor)
'DominantColor(r:3 g:6 b:244 l:3; dominant_color:b; resize_value:16; minimum_percent_difference_of_rgb:10)'
>>> str(dominantcolor)
'b'
>>>
Output dominant color and what their meanings are:
r- Red is the dominant color in the image.g- Green is the dominant color for the image.b- Blue is the dominant color.l- It is lowercase L and it implies that the image is a mostly a grayscale image. L for luminance and most of the image lacks color.n- None of the color out of r, g and b are dominant but the image is not grayscale. It implies that the image has equal regions where 2 or 3 colors dominate, example here. You can check the rgb attribute to decide what to do with such cases.
What are r, g, b and l attributes of DominantColor objects?
The library shrinks the image before checking the dominant color and the default resize value is 256. Thus every image is shrunk to a 256 pixels image. The r,g,b and l attributes indicate the number of pixels which have r,g,b and l as dominating value.
License
Copyright (c) 2022 Akash Mahanty.
Released under the MIT License. See license for details.
Metadata
Release files for imagedominantcolor 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| imagedominantcolor-1.0.1.tar.gz | 5.4 kB | Without provenance | Details for imagedominantcolor-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| imagedominantcolor-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for imagedominantcolor-1.0.1-py3-none-any.whl |
Total release size: 11.3 kB
Release files / imagedominantcolor-1.0.1.tar.gz
| Download URL | imagedominantcolor-1.0.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f37790dfb52402a636231e8e0a1148f241990d4ff75f6b6e7f838885ffef7079
|
|
BLAKE2b-256 checksum How to use checksums |
fe3e504aa527e9a3eb287a5d0d382fcff9b2580af91b45a9fe21dff95be96651
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
|
Release files / imagedominantcolor-1.0.1-py3-none-any.whl
| Download URL | imagedominantcolor-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d890d61f78637f718f5eb6afbd60919317b889c45c5c4133d6bf8e670b18ff6c
|
|
BLAKE2b-256 checksum How to use checksums |
8ccf92931dbe2151fc92db9827dd12da43fc97e6579e3658e847f10e2f5bce67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
|
Security for imagedominantcolor 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.