A comprehensive tool for analyzing colors in images with harmony calculations and multiple color space conversions
Project description
Image Color Analysis Tool
A powerful Python tool for analyzing colors in images, providing detailed information about color distributions, harmonies, and various color space conversions. Perfect for designers, artists, and developers working with color analysis and manipulation.
Quickstart
pip install color-analysis-tool
color-analysis photo.jpg output/
Features
- Comprehensive Color Analysis: Extract and analyze colors from images
- Multiple Color Spaces: Support for RGB, HEX, and CMYK color formats
- Color Harmony: Calculate complementary, analogous, triadic, and tetradic color harmonies
- Color Sorting Options: Sort colors by frequency, hue, saturation, or brightness
- Color Quantization: Reduce images to a meaningful palette (e.g. 32 dominant colors) for faster, cleaner analysis
- Dominant Color Detection: Automatically identify the most prominent color
- Batch Processing: Analyze multiple images recursively in directories, mirroring subdirectory structure
- Flexible Output: Generate reports as plain text or structured JSON
- Format Support: Works with PNG, JPG, TIFF, WebP, and PSD files
- Progress Tracking: Visual progress bars for processing status
- CLI and API: Use as a command-line tool or import as a Python library
- Tested: 50 unit tests covering converters, harmonies, analysis, and output
Installation
From PyPI (Recommended)
pip install color-analysis-tool
From Source
- Clone the repository:
git clone https://github.com/MichailSemoglou/color-analysis-tool.git
cd color-analysis-tool
- Create and activate a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate
- Install the package:
# For regular use
pip install .
# For development (editable install with dev dependencies)
pip install -e ".[dev]"
Usage
Command Line Interface
After installation, you can use the color-analysis command:
# Show all available options
color-analysis --help
# Analyze a single image
color-analysis path/to/image.jpg output/directory
# Process all images in a directory
color-analysis path/to/image/directory output/directory
# Enable verbose logging
color-analysis path/to/image.jpg output/directory -v
# Sort colors by different criteria
color-analysis path/to/image.jpg output/directory -s hue
color-analysis path/to/image.jpg output/directory -s saturation
color-analysis path/to/image.jpg output/directory -s brightness
# Quantize to 32 dominant colors (faster and cleaner for photos)
color-analysis path/to/image.jpg output/directory -c 32
# Output as JSON instead of plain text
color-analysis path/to/image.jpg output/directory -f json
# Combine options
color-analysis path/to/image/directory output/directory -c 64 -s hue -f json -v
# Show version
color-analysis --version
Python API
You can also use the tool as a library in your Python projects:
from color_analysis_tool import ImageAnalyzer
analyzer = ImageAnalyzer()
# Analyze a single image with custom sorting
image_info = analyzer.analyze_image('path/to/image.jpg', sort_by='hue')
# Quantize to 32 colors before analysis (recommended for photos)
image_info = analyzer.analyze_image('path/to/image.jpg', max_colors=32)
# Save as plain text (default)
analyzer.save_analysis('output/directory', image_info)
# Save as JSON
analyzer.save_analysis('output/directory', image_info, output_format='json')
# Process multiple images recursively
analyzer.batch_process('input/directory', 'output/directory', sort_by='frequency')
# Batch with quantization and JSON output
analyzer.batch_process('input/directory', 'output/directory', max_colors=64, output_format='json')
Working with Analysis Results
from color_analysis_tool import ImageAnalyzer, ColorConverter, ColorHarmony
analyzer = ImageAnalyzer()
image_info = analyzer.analyze_image('photo.jpg')
# Access image metadata
print(f"Image: {image_info.filename}")
print(f"Dimensions: {image_info.dimensions}")
print(f"Dominant color: {image_info.dominant_color}")
# Iterate through colors
for color in image_info.colors[:10]: # Top 10 colors
print(f"RGB: {color.rgb}, HEX: {color.hex}, Frequency: {color.frequency}%")
print(f" Complementary: {color.harmonies['complementary']}")
# Use utility classes directly (static methods — no instantiation needed)
cmyk = ColorConverter.rgb_to_cmyk(255, 128, 64)
harmonies = ColorHarmony.find_harmonies((255, 128, 64))
Example Output
The tool generates a detailed analysis file for each image with the following information:
- Image metadata (dimensions, format)
- Dominant color information
- Color frequency analysis with sorting options
- RGB, HEX, and CMYK values for each significant color
- Color harmonies for each major color
Plain text output (-f txt, default):
Image Analysis for example.jpg
Dimensions: 1920x1080
Format: JPEG
Dominant Color: RGB(255, 255, 255)
Colors (sorted by frequency):
Color #1:
RGB: (255, 255, 255)
HEX: #ffffff
CMYK: (0, 0, 0, 0)
Frequency: 35.2%
Color Harmonies:
Complementary:
RGB(0, 0, 0)
Analogous:
RGB(255, 245, 245)
RGB(255, 255, 255)
RGB(245, 255, 255)
Triadic:
RGB(255, 255, 0)
RGB(255, 255, 255)
RGB(0, 255, 255)
Tetradic:
RGB(255, 255, 255)
RGB(255, 0, 255)
RGB(0, 0, 0)
RGB(0, 255, 0)
JSON output (-f json):
{
"filename": "example.jpg",
"dimensions": { "width": 1920, "height": 1080 },
"format": "JPEG",
"sorted_by": "frequency",
"dominant_color": [255, 255, 255],
"colors": [
{
"rgb": [255, 255, 255],
"hex": "#ffffff",
"cmyk": [0, 0, 0, 0],
"frequency": 35.2,
"harmonies": {
"complementary": [[0, 0, 0]],
"analogous": [
[255, 245, 245],
[255, 255, 255],
[245, 255, 255]
],
"triadic": [
[255, 255, 0],
[255, 255, 255],
[0, 255, 255]
],
"tetradic": [
[255, 255, 255],
[255, 0, 255],
[0, 0, 0],
[0, 255, 0]
]
}
}
]
}
Requirements
- Python 3.9 or higher
- Pillow >= 9.0.0
- tqdm >= 4.65.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Development Setup
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/color-analysis-tool.git
cd color-analysis-tool
- Set up development environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e ".[dev]"
- Run tests:
pytest
- Format code:
black color_analysis_tool/
isort color_analysis_tool/
- Type checking:
mypy color_analysis_tool/
Citation
If you use this software in your research, please cite it using the metadata in CITATION.cff:
BibTeX
@software{semoglou_color_analysis_tool,
author = {Semoglou, Michail},
title = {Color Analysis Tool},
version = {1.1.0},
year = {2026},
url = {https://github.com/MichailSemoglou/color-analysis-tool},
doi = {10.5281/zenodo.17848059}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Changelog
See CHANGELOG.md for a history of changes to this project.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file color_analysis_tool-1.1.0.tar.gz.
File metadata
- Download URL: color_analysis_tool-1.1.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
678ba8762da7d29cc30dfd27daf098ecd6aef8cbf3ac20892e0fffd974a032e9
|
|
| MD5 |
93dcd91b293d72c35b4658f2da75580a
|
|
| BLAKE2b-256 |
56fe2c2f9dd85b056b04b1b1e2029c2ff65ae88e6c76bee4a13137dba89f7457
|
Provenance
The following attestation bundles were made for color_analysis_tool-1.1.0.tar.gz:
Publisher:
ci.yml on MichailSemoglou/color-analysis-tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
color_analysis_tool-1.1.0.tar.gz -
Subject digest:
678ba8762da7d29cc30dfd27daf098ecd6aef8cbf3ac20892e0fffd974a032e9 - Sigstore transparency entry: 1202876413
- Sigstore integration time:
-
Permalink:
MichailSemoglou/color-analysis-tool@a93206cbfd276e5faa36974bed2bf782db9d1a51 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MichailSemoglou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@a93206cbfd276e5faa36974bed2bf782db9d1a51 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file color_analysis_tool-1.1.0-py3-none-any.whl.
File metadata
- Download URL: color_analysis_tool-1.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e864bfa277b0f2b18c25cc8343e9ba6b62657ef198f9a17dbff65da648181be1
|
|
| MD5 |
d119a668d06a39f55193de029f971c49
|
|
| BLAKE2b-256 |
ae5495ea9f252e2d2e5366c9c6c708162d32f0fb532465a94ab715015133b53b
|
Provenance
The following attestation bundles were made for color_analysis_tool-1.1.0-py3-none-any.whl:
Publisher:
ci.yml on MichailSemoglou/color-analysis-tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
color_analysis_tool-1.1.0-py3-none-any.whl -
Subject digest:
e864bfa277b0f2b18c25cc8343e9ba6b62657ef198f9a17dbff65da648181be1 - Sigstore transparency entry: 1202876418
- Sigstore integration time:
-
Permalink:
MichailSemoglou/color-analysis-tool@a93206cbfd276e5faa36974bed2bf782db9d1a51 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MichailSemoglou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@a93206cbfd276e5faa36974bed2bf782db9d1a51 -
Trigger Event:
workflow_dispatch
-
Statement type: