pylette

A Python library for extracting color palettes from supplied images.

https://github.com/qtiptip/pylette

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.9%) to scientific vocabulary

Keywords

color color-palette color-scheme colorpicker command-line-interface image-analysis image-processing pillow python visualization-tools

Keywords from Contributors

mesh interpretability sequences projection interactive optim hacking network-simulation
Last synced: 6 months ago · JSON representation ·

Repository

A Python library for extracting color palettes from supplied images.

Basic Info
Statistics
  • Stars: 147
  • Watchers: 1
  • Forks: 14
  • Open Issues: 5
  • Releases: 18
Topics
color color-palette color-scheme colorpicker command-line-interface image-analysis image-processing pillow python visualization-tools
Created over 7 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License Citation

README.md

Pylette

Extract color palettes from images using the command line or Python library

PyPI version PyPI - Downloads Built with Material for MkDocs Dependabot DOI


Documentation: qtiptip.github.io/Pylette

Source code: qTipTip/Pylette


What is Pylette?

Pylette helps you extract color palettes from images. Use the command-line interface for quick tasks or the Python library for more advanced workflows.

Key Features: - Extract palettes from single images or batch process multiple files - Export to JSON format with metadata and hex colors - Support for different colorspaces (RGB, HSV, HLS) - Handle transparent images with alpha channel masking - Fast parallel processing for multiple images - Rich progress display with color previews

Getting Started

Installation

You can easily install Pylette using pip:

shell pip install Pylette

Or if you prefer using uv:

shell uv add Pylette

Command Line Usage

Extract palettes from images using simple commands:

```bash

Extract 5 colors from an image (shows clean table output)

pylette image.jpg

Process multiple images and export to JSON files

pylette *.jpg --export-json --output results/

Extract 8 colors in HSV colorspace with structured export

pylette photo.png --n 8 --colorspace hsv --export-json --output colors.json

Batch process with parallel processing and table display

pylette images/*.png --n 6 --num-threads 4 ```

Example Output: ✓ Extracted 5 colors from sunset.jpg ┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓ ┃ Hex ┃ RGB ┃ Frequency┃ ┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩ │ #FF6B35 │ (255, 107, 53) │ 28.5% │ │ #F7931E │ (247, 147, 30) │ 23.2% │ │ #FFD23F │ (255, 210, 63) │ 18.7% │ │ #06FFA5 │ (6, 255, 165) │ 15.4% │ │ #4ECDC4 │ (78, 205, 196) │ 14.2% │ └──────────┴─────────────────┴──────────┘

Export Options

Control how your palettes are saved:

```bash

Individual JSON files for each image

pylette *.jpg --export-json --output palettes/

Creates: palettes/palette001.json, palettes/palette002.json, etc.

Combined JSON file with all palettes

pylette *.jpg --export-json --output all_colors.json

Export with different colorspace

pylette image.jpg --colorspace hsv --export-json --output hsv_palette.json

Suppress table output, only export JSON

pylette *.png --export-json --output results/ --no-stdout ```

Common Options

```bash

Use different extraction algorithms

pylette image.jpg --mode MedianCut --n 6

Handle transparent images

pylette logo.png --alpha-mask-threshold 128

Customize output

pylette image.jpg --no-stdout --display-colors ```

Python Library

For programmatic usage and advanced workflows:

```python from Pylette import extract_colors

Extract palette with rich metadata

palette = extractcolors(image='image.jpg', palettesize=8)

Access color properties with hex support

for color in palette.colors: print(f"RGB: {color.rgb}") print(f"Hex: {color.hex}") print(f"HSV: {color.hsv}") print(f"Frequency: {color.freq:.2%}")

Export to structured JSON

palette.to_json(filename='palette.json', colorspace='hsv')

Access metadata

print(f"Source: {palette.imagesource}") print(f"Extraction time: {palette.processingstats['extraction_time']:.2f}s")

Simple export method

palette.export('mycolors', colorspace='hls', includemetadata=True) ```

Batch Processing

For processing multiple images programmatically:

```python from Pylette import batchextractcolors

Process multiple images with parallel processing

results = batchextractcolors( images=['image1.jpg', 'image2.png', 'image3.jpg'], palettesize=8, maxworkers=4, mode='KMeans' )

Handle results

for result in results: if result.success and result.palette: print(f"✓ {result.source}: {len(result.palette.colors)} colors") result.palette.export(f"{result.source}_palette") else: print(f"✗ {result.source}: {result.error}") ```

The Python library provides full programmatic access to all CLI features plus detailed metadata and customization options.

JSON Export Format

Pylette exports rich JSON data with semantic field names:

json { "colors": [ { "rgb": [142, 152, 174], "hex": "#8E98AE", "frequency": 0.25 } ], "palette_size": 5, "colorspace": "rgb", "metadata": { "image_source": "photo.jpg", "extraction_params": { "palette_size": 5, "mode": "KMeans" }, "processing_stats": { "extraction_time": 0.234 } } }

Different colorspaces use semantic field names: - RGB: {"rgb": [255, 128, 64], "hex": "#FF8040", "frequency": 0.25} - HSV: {"hsv": [0.08, 0.75, 1.0], "rgb": [255, 128, 64], "hex": "#FF8040", "frequency": 0.25} - HLS: {"hls": [0.08, 0.63, 0.75], "rgb": [255, 128, 64], "hex": "#FF8040", "frequency": 0.25}

Interactive Table Output

When run without --export-json, Pylette displays a clean table:

✓ Extracted 5 colors from photo.jpg ┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓ ┃ Hex ┃ RGB ┃ Frequency┃ ┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩ │ #FF8040 │ (255, 128, 64) │ 25.2% │ │ #4080FF │ (64, 128, 255) │ 30.1% │ └──────────┴─────────────────┴──────────┘

The table automatically adapts to show the chosen colorspace (RGB, HSV, or HLS).

Working with Transparent Images

Handle transparency in both CLI and Python:

```bash

CLI: Exclude pixels with alpha < 128

pylette transparent.png --alpha-mask-threshold 128 ```

```python

Python: Same functionality

from Pylette import extractcolors palette = extractcolors('transparent.png', alphamaskthreshold=128) ```

Why Choose Pylette?

  • Clean, Visual Output: No more raw CSV dumps - see your colors in beautiful tables
  • Rich Metadata: Every palette includes extraction details, timing, and image info
  • Flexible Export: JSON format with semantic field names for easy parsing
  • Batch Ready: Process hundreds of images with parallel processing and progress bars
  • Developer Friendly: Comprehensive Python API with full type hints
  • Modern CLI: Intuitive commands that guide you toward the right options

CLI Reference

For complete usage information:

bash pylette --help

All Options

``` Usage: pylette [OPTIONS] IMAGE_SOURCES...

Arguments: IMAGE_SOURCES... Images, URLs, or directories to process [required]

Options: --mode [KMeans|MedianCut] Extraction algorithm [default: KMeans] --n INTEGER Number of colors to extract [default: 5] --sort-by [frequency|luminance] Sort colors by [default: luminance] --colorspace [rgb|hsv|hls] Color space [default: rgb] --export-json Export to JSON format --output PATH Output file or directory for JSON export --alpha-mask-threshold [0-255] Alpha threshold for transparency --num-threads INTEGER Parallel processing threads --display-colors Show palette images --no-stdout Suppress table output --help Show help message ```

Owner

  • Name: Ivar Stangeby
  • Login: qTipTip
  • Kind: user
  • Location: Oslo
  • Company: Cognite

Mathematics student gone software engineer.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Stangeby"
  given-names: "Ivar"
  orcid: "https://orcid.org/0000-0002-7697-7526"
title: "Pylette"
version: 4.0.1
doi: 10.5281/zenodo.14757253
date-released: 2025-01-27
date-published: 2024-02-09
url: "https://github.com/qtiptip/pylette"

GitHub Events

Total
  • Create event: 40
  • Issues event: 14
  • Release event: 9
  • Watch event: 38
  • Delete event: 21
  • Issue comment event: 32
  • Push event: 79
  • Pull request review event: 12
  • Pull request event: 64
  • Fork event: 4
Last Year
  • Create event: 40
  • Issues event: 14
  • Release event: 9
  • Watch event: 38
  • Delete event: 21
  • Issue comment event: 32
  • Push event: 79
  • Pull request review event: 12
  • Pull request event: 64
  • Fork event: 4

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 112
  • Total Committers: 3
  • Avg Commits per committer: 37.333
  • Development Distribution Score (DDS): 0.134
Past Year
  • Commits: 37
  • Committers: 3
  • Avg Commits per committer: 12.333
  • Development Distribution Score (DDS): 0.405
Top Committers
Name Email Commits
Ivar Stangeby i****y@g****m 97
dependabot[bot] 4****] 14
Bamigbade Opeyemi b****i@g****m 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 21
  • Total pull requests: 91
  • Average time to close issues: 2 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 10
  • Total pull request authors: 6
  • Average comments per issue: 0.9
  • Average comments per pull request: 0.59
  • Merged pull requests: 58
  • Bot issues: 0
  • Bot pull requests: 41
Past Year
  • Issues: 13
  • Pull requests: 62
  • Average time to close issues: 19 days
  • Average time to close pull requests: 5 days
  • Issue authors: 4
  • Pull request authors: 4
  • Average comments per issue: 0.54
  • Average comments per pull request: 0.63
  • Merged pull requests: 37
  • Bot issues: 0
  • Bot pull requests: 32
Top Authors
Issue Authors
  • qTipTip (12)
  • jmillandev (2)
  • mcioffi (1)
  • AnnMarieW (1)
  • WantToLearnJapanese (1)
  • Leterax (1)
  • pranavAbe (1)
  • chrisrogers3d (1)
  • softmarshmallow (1)
  • VitorCMatias (1)
  • Nafeij (1)
Pull Request Authors
  • qTipTip (60)
  • dependabot[bot] (48)
  • gaelgoth (4)
  • opeyemibami (2)
  • Nafeij (1)
Top Labels
Issue Labels
enhancement (3)
Pull Request Labels
dependencies (47) github-actions (1)

Dependencies

poetry.lock pypi
  • cfgv 3.3.1 develop
  • distlib 0.3.4 develop
  • filelock 3.4.2 develop
  • identify 2.4.9 develop
  • nodeenv 1.6.0 develop
  • platformdirs 2.5.0 develop
  • pre-commit 2.17.0 develop
  • pyyaml 6.0 develop
  • six 1.16.0 develop
  • toml 0.10.2 develop
  • virtualenv 20.13.1 develop
  • joblib 1.1.0
  • numpy 1.22.2
  • pillow 9.0.1
  • pyqt5 5.15.6
  • pyqt5-qt5 5.15.2
  • pyqt5-sip 12.9.1
  • scikit-learn 1.0.2
  • scipy 1.8.0
  • threadpoolctl 3.1.0
pyproject.toml pypi
  • pre-commit ^2.17.0 develop
  • Pillow ^9.0.1
  • PyQt5 ^5.15.6
  • numpy ^1.22.2
  • python ~3.8
  • scikit-learn ^1.0.2
.github/workflows/publish-to-pypi.yaml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • pypa/gh-action-pypi-publish release/v1 composite
  • snok/install-poetry v1.3.3 composite