#color #image #clustering #svg

app dominant-colours

Extract dominant colours from images using k-means clustering

2 unstable releases

new 0.2.0 Jan 12, 2025
0.1.0 Jan 10, 2025

#242 in Images

50 downloads per month

MIT license

12KB
200 lines

dominant-colours

License: MIT

A command line tool that extracts dominant colours from images using k-means clustering. Unlike simpler color quantization algorithms, this tool uses machine learning to find natural color clusters and reports their prevalence in the image.

Features

  • Uses k-means clustering to find natural color groupings
  • Reports the percentage of the image occupied by each color
  • Generates SVG color swatches
  • Fast execution using optimized Rust libraries

Installation

cargo install --path .

Usage

# Basic usage - prints RGB values
dominant-colours image.jpg

# Specify number of colors to extract
dominant-colours -c 8 image.jpg

# Generate a color swatch
dominant-colours --swatch image.jpg

# Specify swatch output file
dominant-colours -s -o my-colors.svg image.jpg

Dependencies

  • image: Image loading and manipulation
  • linfa-clustering: Machine learning algorithms
  • clap: Command line argument parsing

Dependencies

~13MB
~222K SLoC