Skip to main content

Extract colors from an image. Colors are grouped based on visual similarities using the CIE76 formula.

Project description

Command-line tool to extract colors from an image. The result will presented in two formats, text and image.

The text result will provide the usage of each color in the number of pixels and percentage. While the image will provide a palette for a visual representation.

1 Installation

1.1 Package

$ pip install extcolors

1.2 Manually

  1. Download repository as zip.

  2. Unpack zip into folder.

  3. Enter folder.

  4. Run the following command:

    $ pip install .

2 Usage

2.1 Input - Console

To use the application provide a path to the image that the application should extract colors from. In the following example the image is in the folder we are executing the command and the name of the image is gameboy.png:

$ extcolors gameboy.png

In this example gameboy.png refers to the following image created by Rebecca Machamer.

http://cairns.se/extcolors/gameboy.png

2.2 Input - Script

To use the application provide a path to the image that the application should extract colors from. In the following example the image is in the folder we are executing the command and the name of the image is gameboy.png:

>>> import extcolors
>>> colors, pixel_count = extcolors.extract("gameboy.png")
>>> print(colors)
[((0, 172, 170), 385938), ((245, 245, 245), 59971), ((82, 90, 92), 17564), ((102, 184, 52), 15096), ((236, 27, 111), 1270), ((255, 180, 0), 121), ((252, 94, 158), 40)]

2.3 Output - Text

When the application is done it will output information about the execution. Probably the most relevant information is the [RESULT]-section that contains the extracted colors in RGB values and their occurrence rate presented in percentages.

Output based on gameboy.png:

Extracted colors:
(245, 245, 245):  12.49% (59971)
(82, 90, 92)   :   3.66% (17564)
(102, 184, 52) :   3.15% (15096)
(236, 27, 111) :   0.26% (1270)
(255, 180, 0)  :   0.03% (121)
(252, 94, 158) :   0.01% (40)

Pixels in output: 480000 of 480000

2.4 Output - Image

When the application is done it will also create an image in the directory where the command was executed. The image will contain the colors that where extracted sorted based on their occurrence rate, wrapping from from left to right. The image will use the name of the original image appended with a time stamp of when the execution took place.

Output based on gameboy.png:

http://cairns.se/extcolors/gameboy-result-default.png

3 Additional Options

Generated output from the command-line argument extcolors --help.

usage: extcolors [-h] [--version] [-t [N]] [-l [N]] [-o {all,image,text}] PATH

Extract colors from a specified image. Colors are grouped based on visual
similarities using the CIE76 formula.

positional arguments:
  PATH

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -t [N], --tolerance [N]
                        Group colors to limit the output and give a better
                        visual representation. Based on a scale from 0 to 100.
                        Where 0 won't group any color and 100 will group all
                        colors into one. Tolerance 0 will also bypass all
                        conversion. Defaults to 32.
  -l [N], --limit [N]   Upper limit to the number of extracted colors
                        presented in the output.
  -o {all,image,text}, --output {all,image,text}
                        Format(s) that the extracted colors should presented
                        in.

4 Known Issues

Performance

When an image contains a large amount of different colors, which most do, the performance slows to a halt. If the grouping of colors is not desired/required then a workaround is to set the tolerance levels to zero. Setting the tolerance to specifically zero will make the application skip any comparisons from being made and become a simple counter resulting in much greater speeds.

Example, an image (3840x2160) containing about 340k unique colors will take two hours to complete with a tolerance level of 32 (the default value). However with a tolerance level of zero it will take ten seconds.

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

extcolors-0.1.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

extcolors-0.1.3-py2-none-any.whl (9.4 kB view details)

Uploaded Python 2

File details

Details for the file extcolors-0.1.3.tar.gz.

File metadata

  • Download URL: extcolors-0.1.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15rc1

File hashes

Hashes for extcolors-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d1af61b38a6f0a46f54c2f0ea32a555d7608c71e5b8a0e71f8bb0cd000a5d833
MD5 d4d0a0061f57e508136359592d8522b4
BLAKE2b-256 77710c22724d39a8f7998396b393fc28d17c49c431f7057566ebd77fc2405dd9

See more details on using hashes here.

File details

Details for the file extcolors-0.1.3-py2-none-any.whl.

File metadata

  • Download URL: extcolors-0.1.3-py2-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15rc1

File hashes

Hashes for extcolors-0.1.3-py2-none-any.whl
Algorithm Hash digest
SHA256 5f6c5cd64b238bddb7b14da643e0e34e1dc359f306e293d811b1f04b3bf87f19
MD5 fc3608d692dd4c7144509bf6eecefda9
BLAKE2b-256 333df9c795f107201f8f183db8e7e05a7106c1041d50a1f66768fd55d76cd4c0

See more details on using hashes here.

Supported by

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