Disclaimer: This project is vibe coded. It works, but don't expect enterprise-grade code quality or extensive documentation. Use at your own risk! 🎨
A Python application that extracts dominant colors from images using three different approaches:
- ClassicMLColorPaletteAgent: Local K-means clustering (no internet required)
- SimpleColorPaletteAgent (OpenAI): GPT-4o via OpenAI API (direct color extraction)
- SimpleColorPaletteAgent (OpenRouter): GPT-4o + Qwen-VL via OpenRouter API (spatial reasoning with color localization)
The tool analyzes images and extracts 5 representative colors, displaying them in a visual format. You can see the results in two ways:
The matplotlib version shows the original image with numbered circles marking where each color was found, alongside a vertical color palette with hex codes and color names at the bottom.
The web application provides a clean, minimalistic interface where you can upload images or provide URLs. It displays the original image with color position markers and shows the extracted colors as interactive swatches with descriptive names, hex codes, and RGB values.
- Three extraction modes:
- Classic K-means clustering (offline, fast)
- OpenAI GPT-4o (direct color extraction with descriptions)
- OpenRouter with spatial reasoning (GPT-4o + Qwen-VL for precise color localization)
- Extracts 5 dominant colors from images
- Automatically resizes images to 1024px on the larger side for faster processing (ML agent)
- Visualizes results with matplotlib or web interface
- Color descriptions for AI-based agents
- Uses
uvfor package management
- Install dependencies using
uv:
uv pip install -e .- Create a
.envfile in the project root with your API keys (only needed for AI agents):
OPENAI_API_KEY=your-openai-api-key-here
OPENROUTER_API_KEY=your-openrouter-api-key-hereNote:
- For the classic agent, no API keys are needed
- For OpenAI agent, you only need
OPENAI_API_KEY - For OpenRouter agent, you need
OPENROUTER_API_KEY(used for both GPT-4o and Qwen-VL)
uv run python agent.py images/1.jpegThis uses local K-means clustering. No API keys needed, works completely offline.
uv run python agent.py images/1.jpeg --agent openaiUses GPT-4o to extract colors directly. Returns colors with vivid descriptions. Requires OPENAI_API_KEY in .env.
uv run python agent.py images/1.jpeg --agent openrouterUses GPT-4o for color descriptions and Qwen-VL for precise pixel localization. Shows numbered circles on the image marking where each color was found. Requires OPENROUTER_API_KEY in .env.
uv run python app.pyStarts a Flask web server on http://localhost:5000. The web app uses the OpenRouter agent by default. You can:
- Upload images from your computer
- Provide image URLs
- View results with interactive color swatches
uv run python agent.py <image_path> [options]
Options:
--agent {classic,openai,openrouter} Agent to use (default: classic)
-n, --num-colors N Number of colors to extract (default: 5, only for classic)
-o, --output PATH Path to save the visualization (optional)# Classic agent with 8 colors
uv run python agent.py images/1.jpeg -n 8
# OpenAI agent, save to file
uv run python agent.py images/1.jpeg --agent openai -o output.png
# OpenRouter agent
uv run python agent.py images/1.jpeg --agent openrouterfrom agent import ClassicMLColorPaletteAgent
agent = ClassicMLColorPaletteAgent(n_colors=5)
colors = agent.visualize('path/to/image.jpg')
# Returns: numpy array of RGB colors (shape: (n_colors, 3))from agent import SimpleColorPaletteAgent
# Using OpenAI (default)
agent = SimpleColorPaletteAgent(use_openrouter=False)
colors, points, descriptions = agent.extract_colors('path/to/image.jpg')
# Returns: (colors, None, descriptions) where colors is list of dicts with 'hex' and 'rgb'
# Using OpenRouter (spatial reasoning)
agent = SimpleColorPaletteAgent(use_openrouter=True)
colors, points, descriptions = agent.extract_colors('path/to/image.jpg')
# Returns: (colors, points, descriptions) where points are [x, y] coordinates
# Visualize
agent.visualize('path/to/image.jpg', output_path='output.png')- Returns numpy array of RGB values:
[[R, G, B], ...] - No color names (uses generic "Color 1", "Color 2", etc.)
- No position markers
- Returns list of color dictionaries:
[{'hex': '#FF5733', 'rgb': [255, 87, 51]}, ...] - Includes vivid color descriptions (e.g., "glowing amber moon")
- No position markers (direct extraction)
- Returns list of color dictionaries with position coordinates
- Includes vivid color descriptions
- Shows numbered circles on image marking color locations
- Python 3.8+
- scikit-learn (for ClassicMLColorPaletteAgent)
- matplotlib
- numpy
- Pillow
- openai (for SimpleColorPaletteAgent)
- python-dotenv (for loading .env file)
- flask (for web app)
- requests (for web app URL downloads)
colorpalette/
├── agent.py # Color extraction agents
├── main.py # Main CLI entry point
├── app.py # Flask web application
├── utils.py # Shared utility functions
├── config.py # Configuration constants
├── templates/ # Web app templates
│ └── index.html
├── images/ # Sample images and screenshots
└── README.md # This file
Vibe coded, use freely! 🎨

