pylette-windows


Namepylette-windows JSON
Version 3.0.0 PyPI version JSON
download
home_page
SummaryPylette for Windows
upload_time2023-07-25 17:22:50
maintainer
docs_urlNone
author
requires_python>=3.11.4
licenseMIT License Copyright (c) [2018] [Ivar Stangeby] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords palette color image
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pylette [WIP]

[![PyPI version](https://badge.fury.io/py/Pylette.svg)](https://badge.fury.io/py/Pylette)
[![Downloads](http://pepy.tech/badge/pylette)](http://pepy.tech/project/pylette)

A color palette extractor written in Python using KMeans clustering.

## Motivation

Working with computer graphics and visualizations, one often needs a way of specifying a set of colors
with a certain visual appeal. Such a set of colors is often called a *color palette*. The aim of this
library is to easily extract a set of colors from a supplied image, with support for the various color modes (RGB, RGBa, HSV, etc).
Dabbling in generative art, the need often arises for being able to pick colors at random from a palette.
Pylette supports this, both picking colors uniformly, but also using the color frequency from the original image as probabilities.



#### Other color palette related Python-libraries:
1. [Color Thief](https://github.com/fengsp/color-thief-py): Extraction of color palettes using the median cut algorithm.
2. [Palettable](https://pypi.org/project/palettable/): Generation of matplotlib compatible color schemes
3. [Colorgram](https://github.com/obskyr/colorgram.py): Extraction of colors from images (similar to the intended use of this library),
however, I was unable to install this.

## Installation

Pylette is available in the python package index (PyPi), and can be installed using `pip`:

```shell
pip install Pylette
```

## Basic usage

A `Palette` object is created by calling the `extract_colors` function.

```python
from Pylette import extract_colors

palette = extract_colors('image.jpg', palette_size=10, resize=True)
palette = extract_colors('image.jpg', palette_size=10, resize=True, mode='MC', sort_mode='luminance')
```

This yields a palette of ten colors, and the `resize` flag tells Pylette to resize the image to a more manageable size before
beginning color extraction. This significantly speeds up the extraction, but reduces the faithfulness of the color palette.
One can choose between color quantization using K-Means (default) or Median-Cut algorithms, by setting in the `mode`-parameter. One can also specify to alternatively sort the color palette by the luminance (percieved brightness).

The palette object supports indexing and iteration, and the colors are sorted from highest to lowest frequency by default.
E.g, the following snippet will fetch the most common, and least common
color in the picture if the palette was sorted by frequency, or the darkest to lightest color if sorted by luminance:
```python
most_common_color = palette[0]
least_common_color = palette[-1]
three_most_common_colors = palette[:3]
```
As seen, slicing is also supported.

The Palette object contains a list of Color objects, which contains a representation of the color in various color modes, with RGB being the default. Accessing the color attributes is easy:

```python
color = palette[0]

print(color.rgb)
print(color.hls)
print(color.hsv)
```

To display the extracted color palette, simply call the `display`-method, which optionally takes a flag for saving the palette to an image file.
The palette can be dumped to a CSV-file as well, where each row represents the RGB values and the corresponding color frequency (optional).
```python
palette.display(save_to_file=False)
palette.to_csv(filename='color_palette.csv', frequency=True)
```

In order to pick colors from the palette at random, Pylette offers the `random_color`-method, which supports both drawing
uniformly, and from the original color distribution, given by the frequencies of the extracted colors:

```python
random_color = palette.random_color(N=1, mode='uniform')
random_colors = palette.random_color(N=100, mode='frequency')
```

## Example Palettes

A selection of example palettes. Each palette is sorted by luminance (percieved brightness). The top row corresponds to extraction using K-Means, and the bottom row corresponds to Median-Cut extraction.

Original Image  | Extracted Palette
:--------------:|:-----------------:
<img src="https://images.unsplash.com/photo-1534535009397-1fb0a46440f1?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=0de8fee9f4e6aa3d55fef987734a0787&auto=format&fit=crop&w=1234&q=80" width=200 height=200> | ![](example_imgs/jason_leung_palette_kmeans.jpg) ![](example_imgs/jason_leung_palette_mediancut.jpg)
<img src="https://images.unsplash.com/photo-1534547774987-e59593542e1e?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e8e5af1676517ac1ef8067f97a206415&auto=format&fit=crop&w=1234&q=80" width=200 height=200> | ![](example_imgs/alex_perez_palette_kmeans.jpg)  ![](example_imgs/alex_perez_palette_mediancut.jpg)
<img src="https://images.unsplash.com/photo-1534537841395-2e594ba9ed4a?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=34ad54d1ba5d88b42abf43219c905c78&auto=format&fit=crop&w=1234&q=80" width=200 height=200> | ![](example_imgs/josh_hild_palette_kmeans.jpg)   ![](example_imgs/josh_hild_palette_mediancut.jpg)

## Command Line Tool

The new version of Pylette also comes bundled with a command line tool, which can be used to extract color palettes from the command line.

```shell script
usage: pylette [-h] [--mode {KM,MC}] [--n N] [--sort_by {luminance,frequency}]
               [--stdout STDOUT] [--colorspace {rgb,hsv,hls}]
               [--out_filename OUT_FILENAME] [--display-colors DISPLAY_COLORS]
               filename

positional arguments:
  filename              path to image file

optional arguments:
  -h, --help            show this help message and exit
  --mode {KM,MC}        extraction_mode (KMeans/MedianCut (default: KM)
  --n N                 the number of colors to extract (default: 5)
  --sort_by {luminance,frequency}
                        sort by luminance or frequency (default: luminance)
  --stdout STDOUT       whether to display the extracted color values in the
                        stdout (default: True)
  --colorspace {rgb,hsv,hls}
                        color space to represent colors in (default: RGB)
  --out_filename OUT_FILENAME
                        where to save the csv file (default: None)
  --display-colors DISPLAY_COLORS
                        Open a window displaying the extracted palette
                        (default: False)
```

## Pylette GUI

Pylette now comes bundled with a barebones graphical user interface, using PyQt5 as the backend.
From the command line, the GUI can be accessed by running

```shell script
pylette_gui
```

opens the interface. Import an image by clicking

```shell script
File -> Open Image
```
select the number of colors, and hit "Extract Colors".
Hover over each extracted color to see the corresponding RGB values.

![](example_imgs/pylette_gui.png)

In future versions, automatic copy of hex-values to clipboard, and additional
options for the extraction will be available in the GUI menus.

## Under the hood

Currently, Pylette uses KMeans for the color quantization. There are plans for implementing other color quantization schemes, like:

1. Median-cut [Implemented]
2. Octree
3. Modified minmax

The article [*Improving the Performance of K-Means for Color Quantization*](https://arxiv.org/pdf/1101.0395.pdf) gives a
nice overview of available methods.

## Feedback
Any feedback and suggestions is much appreciated.
This is very much a work in progress.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pylette-windows",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11.4",
    "maintainer_email": "",
    "keywords": "palette,color,image",
    "author": "",
    "author_email": "Austin Bryant <c00481025@louisiana.edu>",
    "download_url": "https://files.pythonhosted.org/packages/b0/57/069c3a13dbb35da13f412df30f42c5bc51405383ad03228bb74f1b91a4e6/pylette-windows-3.0.0.tar.gz",
    "platform": null,
    "description": "# Pylette [WIP]\r\n\r\n[![PyPI version](https://badge.fury.io/py/Pylette.svg)](https://badge.fury.io/py/Pylette)\r\n[![Downloads](http://pepy.tech/badge/pylette)](http://pepy.tech/project/pylette)\r\n\r\nA color palette extractor written in Python using KMeans clustering.\r\n\r\n## Motivation\r\n\r\nWorking with computer graphics and visualizations, one often needs a way of specifying a set of colors\r\nwith a certain visual appeal. Such a set of colors is often called a *color palette*. The aim of this\r\nlibrary is to easily extract a set of colors from a supplied image, with support for the various color modes (RGB, RGBa, HSV, etc).\r\nDabbling in generative art, the need often arises for being able to pick colors at random from a palette.\r\nPylette supports this, both picking colors uniformly, but also using the color frequency from the original image as probabilities.\r\n\r\n\r\n\r\n#### Other color palette related Python-libraries:\r\n1. [Color Thief](https://github.com/fengsp/color-thief-py): Extraction of color palettes using the median cut algorithm.\r\n2. [Palettable](https://pypi.org/project/palettable/): Generation of matplotlib compatible color schemes\r\n3. [Colorgram](https://github.com/obskyr/colorgram.py): Extraction of colors from images (similar to the intended use of this library),\r\nhowever, I was unable to install this.\r\n\r\n## Installation\r\n\r\nPylette is available in the python package index (PyPi), and can be installed using `pip`:\r\n\r\n```shell\r\npip install Pylette\r\n```\r\n\r\n## Basic usage\r\n\r\nA `Palette` object is created by calling the `extract_colors` function.\r\n\r\n```python\r\nfrom Pylette import extract_colors\r\n\r\npalette = extract_colors('image.jpg', palette_size=10, resize=True)\r\npalette = extract_colors('image.jpg', palette_size=10, resize=True, mode='MC', sort_mode='luminance')\r\n```\r\n\r\nThis yields a palette of ten colors, and the `resize` flag tells Pylette to resize the image to a more manageable size before\r\nbeginning color extraction. This significantly speeds up the extraction, but reduces the faithfulness of the color palette.\r\nOne can choose between color quantization using K-Means (default) or Median-Cut algorithms, by setting in the `mode`-parameter. One can also specify to alternatively sort the color palette by the luminance (percieved brightness).\r\n\r\nThe palette object supports indexing and iteration, and the colors are sorted from highest to lowest frequency by default.\r\nE.g, the following snippet will fetch the most common, and least common\r\ncolor in the picture if the palette was sorted by frequency, or the darkest to lightest color if sorted by luminance:\r\n```python\r\nmost_common_color = palette[0]\r\nleast_common_color = palette[-1]\r\nthree_most_common_colors = palette[:3]\r\n```\r\nAs seen, slicing is also supported.\r\n\r\nThe Palette object contains a list of Color objects, which contains a representation of the color in various color modes, with RGB being the default. Accessing the color attributes is easy:\r\n\r\n```python\r\ncolor = palette[0]\r\n\r\nprint(color.rgb)\r\nprint(color.hls)\r\nprint(color.hsv)\r\n```\r\n\r\nTo display the extracted color palette, simply call the `display`-method, which optionally takes a flag for saving the palette to an image file.\r\nThe palette can be dumped to a CSV-file as well, where each row represents the RGB values and the corresponding color frequency (optional).\r\n```python\r\npalette.display(save_to_file=False)\r\npalette.to_csv(filename='color_palette.csv', frequency=True)\r\n```\r\n\r\nIn order to pick colors from the palette at random, Pylette offers the `random_color`-method, which supports both drawing\r\nuniformly, and from the original color distribution, given by the frequencies of the extracted colors:\r\n\r\n```python\r\nrandom_color = palette.random_color(N=1, mode='uniform')\r\nrandom_colors = palette.random_color(N=100, mode='frequency')\r\n```\r\n\r\n## Example Palettes\r\n\r\nA selection of example palettes. Each palette is sorted by luminance (percieved brightness). The top row corresponds to extraction using K-Means, and the bottom row corresponds to Median-Cut extraction.\r\n\r\nOriginal Image  | Extracted Palette\r\n:--------------:|:-----------------:\r\n<img src=\"https://images.unsplash.com/photo-1534535009397-1fb0a46440f1?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=0de8fee9f4e6aa3d55fef987734a0787&auto=format&fit=crop&w=1234&q=80\" width=200 height=200> | ![](example_imgs/jason_leung_palette_kmeans.jpg) ![](example_imgs/jason_leung_palette_mediancut.jpg)\r\n<img src=\"https://images.unsplash.com/photo-1534547774987-e59593542e1e?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e8e5af1676517ac1ef8067f97a206415&auto=format&fit=crop&w=1234&q=80\" width=200 height=200> | ![](example_imgs/alex_perez_palette_kmeans.jpg)  ![](example_imgs/alex_perez_palette_mediancut.jpg)\r\n<img src=\"https://images.unsplash.com/photo-1534537841395-2e594ba9ed4a?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=34ad54d1ba5d88b42abf43219c905c78&auto=format&fit=crop&w=1234&q=80\" width=200 height=200> | ![](example_imgs/josh_hild_palette_kmeans.jpg)   ![](example_imgs/josh_hild_palette_mediancut.jpg)\r\n\r\n## Command Line Tool\r\n\r\nThe new version of Pylette also comes bundled with a command line tool, which can be used to extract color palettes from the command line.\r\n\r\n```shell script\r\nusage: pylette [-h] [--mode {KM,MC}] [--n N] [--sort_by {luminance,frequency}]\r\n               [--stdout STDOUT] [--colorspace {rgb,hsv,hls}]\r\n               [--out_filename OUT_FILENAME] [--display-colors DISPLAY_COLORS]\r\n               filename\r\n\r\npositional arguments:\r\n  filename              path to image file\r\n\r\noptional arguments:\r\n  -h, --help            show this help message and exit\r\n  --mode {KM,MC}        extraction_mode (KMeans/MedianCut (default: KM)\r\n  --n N                 the number of colors to extract (default: 5)\r\n  --sort_by {luminance,frequency}\r\n                        sort by luminance or frequency (default: luminance)\r\n  --stdout STDOUT       whether to display the extracted color values in the\r\n                        stdout (default: True)\r\n  --colorspace {rgb,hsv,hls}\r\n                        color space to represent colors in (default: RGB)\r\n  --out_filename OUT_FILENAME\r\n                        where to save the csv file (default: None)\r\n  --display-colors DISPLAY_COLORS\r\n                        Open a window displaying the extracted palette\r\n                        (default: False)\r\n```\r\n\r\n## Pylette GUI\r\n\r\nPylette now comes bundled with a barebones graphical user interface, using PyQt5 as the backend.\r\nFrom the command line, the GUI can be accessed by running\r\n\r\n```shell script\r\npylette_gui\r\n```\r\n\r\nopens the interface. Import an image by clicking\r\n\r\n```shell script\r\nFile -> Open Image\r\n```\r\nselect the number of colors, and hit \"Extract Colors\".\r\nHover over each extracted color to see the corresponding RGB values.\r\n\r\n![](example_imgs/pylette_gui.png)\r\n\r\nIn future versions, automatic copy of hex-values to clipboard, and additional\r\noptions for the extraction will be available in the GUI menus.\r\n\r\n## Under the hood\r\n\r\nCurrently, Pylette uses KMeans for the color quantization. There are plans for implementing other color quantization schemes, like:\r\n\r\n1. Median-cut [Implemented]\r\n2. Octree\r\n3. Modified minmax\r\n\r\nThe article [*Improving the Performance of K-Means for Color Quantization*](https://arxiv.org/pdf/1101.0395.pdf) gives a\r\nnice overview of available methods.\r\n\r\n## Feedback\r\nAny feedback and suggestions is much appreciated.\r\nThis is very much a work in progress.\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) [2018] [Ivar Stangeby]  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Pylette for Windows",
    "version": "3.0.0",
    "project_urls": {
        "Homepage": "https://github.com/IntoThatGoodNight/Pylette-Windows-Fork"
    },
    "split_keywords": [
        "palette",
        "color",
        "image"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b3c041e759218a9d339768a7d27770b75deab5d9b71ee5207499a022167ed184",
                "md5": "2de338bec190d784b3b9e2f4cb32e6fa",
                "sha256": "230e476cea6ee0f4f98a39b1fb319d42214c64bd236ab93f3f16ac6b4e1b4cd8"
            },
            "downloads": -1,
            "filename": "pylette_windows-3.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2de338bec190d784b3b9e2f4cb32e6fa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11.4",
            "size": 12317,
            "upload_time": "2023-07-25T17:22:49",
            "upload_time_iso_8601": "2023-07-25T17:22:49.879573Z",
            "url": "https://files.pythonhosted.org/packages/b3/c0/41e759218a9d339768a7d27770b75deab5d9b71ee5207499a022167ed184/pylette_windows-3.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b057069c3a13dbb35da13f412df30f42c5bc51405383ad03228bb74f1b91a4e6",
                "md5": "957d6b0cfd24958f7b0161b04843cba5",
                "sha256": "6e0158238558fcd337f8ee02a4175a3582dc3202fa443b80551420366bec6e02"
            },
            "downloads": -1,
            "filename": "pylette-windows-3.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "957d6b0cfd24958f7b0161b04843cba5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11.4",
            "size": 13389,
            "upload_time": "2023-07-25T17:22:50",
            "upload_time_iso_8601": "2023-07-25T17:22:50.999462Z",
            "url": "https://files.pythonhosted.org/packages/b0/57/069c3a13dbb35da13f412df30f42c5bc51405383ad03228bb74f1b91a4e6/pylette-windows-3.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-25 17:22:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "IntoThatGoodNight",
    "github_project": "Pylette-Windows-Fork",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pylette-windows"
}
        
Elapsed time: 0.09243s