High-performance color extraction library for Python
MareArts XColor is a powerful color extraction library that uses advanced clustering algorithms to extract dominant colors from images. It features both CPU and GPU acceleration, multiple color space support, and intelligent preprocessing for accurate color analysis.
pip install marearts-xcolor# For CUDA 11.x
pip install marearts-xcolor[gpu] cupy-cuda11x
# For CUDA 12.x
pip install marearts-xcolor[gpu] cupy-cuda12x- Python 3.9, 3.10, 3.11, or 3.12
- Operating System: Windows, macOS, or Linux
- Architecture: x86_64 or ARM64
from marearts_xcolor import ColorExtractor
# Create extractor instance
extractor = ColorExtractor()
# Extract 5 dominant colors from an image
colors = extractor.extract_colors("your_image.jpg")
# Print results
for color in colors:
print(f"RGB: {color['rgb']}, Percentage: {color['percentage']:.2f}%")from marearts_xcolor import ColorExtractor
# Enable GPU acceleration (automatically falls back to CPU if unavailable)
extractor = ColorExtractor(
n_colors=7,
algorithm='dbscan',
lab_space=True,
use_gpu='auto'
)
# Extract colors
colors = extractor.extract_colors("image.jpg")# Basic usage
xcolor image.jpg --colors 5
# Advanced options
xcolor image.jpg --colors 8 --algorithm dbscan --fast
# Batch processing
xcolor *.jpg --output results.json --gpu auto- Multiple Algorithms: K-means and DBSCAN clustering
- Color Spaces: RGB and LAB support
- Smart Preprocessing: CLAHE enhancement and bilateral filtering
- Accurate Results: Perceptually uniform color extraction
- GPU Acceleration: Optional CUDA support for 10-50x speedup
- Optimized Implementation: Cython-compiled with C++ backend
- Smart Fallback: Automatic CPU fallback when GPU unavailable
- Batch Processing: Efficient processing of multiple images
- Pure Python API: Easy integration with existing projects
- Mask Support: Extract colors from specific regions
- Color Similarity: Find similar colors using perceptual metrics
- Export Options: JSON, CSV, and image outputs
from marearts_xcolor import ColorExtractor
import json
extractor = ColorExtractor(n_colors=5, use_gpu='auto')
# Analyze product image
colors = extractor.extract_colors("product.jpg")
# Save results
with open('product_colors.json', 'w') as f:
json.dump(colors, f, indent=2)import glob
from marearts_xcolor import ColorExtractor
extractor = ColorExtractor(n_colors=5, use_gpu='auto')
# Process all images in directory
for image_path in glob.glob("images/*.jpg"):
colors = extractor.extract_colors(image_path)
print(f"\n{image_path}:")
for color in colors:
print(f" {color['hex']} - {color['percentage']:.1f}%")from marearts_xcolor import ColorExtractor
# Extract colors from reference image
extractor_ref = ColorExtractor(n_colors=5)
reference_colors = extractor_ref.extract_colors("reference.jpg")
# Extract more colors from target image
extractor_target = ColorExtractor(n_colors=10)
target_colors = extractor_target.extract_colors("target.jpg")
# Analyze similarity
for ref_color in reference_colors:
similar = extractor.find_similar_colors(
ref_color['rgb'],
target_colors,
threshold=10.0 # Delta-E threshold
)
print(f"Similar to {ref_color['hex']}: {len(similar)} colors found")marearts-xcolor/
βββ examples/ # Complete code examples
β βββ README.md # Examples documentation
β βββ basic_usage.py # Simple color extraction
β βββ gpu_usage.py # GPU acceleration examples
β βββ advanced_usage.py # Advanced features
β βββ integration_examples.py # Integration with other libraries
β βββ webcam_color_extractor.py # Real-time webcam demo
β βββ advanced_webcam_demo.py # Webcam demo with video recording
β βββ cli_usage.sh # Command-line examples
βββ sample_images/ # Test images
βββ sample_image.jpg
βββ product_example.jpg
βββ color_test_image.jpg
βββ sample_mask.jpg
| Parameter | Options | Description |
|---|---|---|
n_colors |
int (e.g., 1-20) | Number of colors to extract |
algorithm |
'kmeans', 'dbscan' | Clustering algorithm |
lab_space |
True/False | Use LAB color space (True) or RGB (False) |
use_gpu |
'auto', 'force', 'never' | GPU acceleration mode |
preprocessing |
True/False | Enable CLAHE enhancement and bilateral filtering |
- Use LAB color space for perceptually accurate colors
- Enable preprocessing for images with poor lighting
- GPU acceleration provides significant speedup for large images
- DBSCAN clustering works better for images with distinct color regions
# Check GPU availability
from marearts_xcolor.gpu_utils import get_gpu_info
print(get_gpu_info())# For CPU-only installation
pip install marearts-xcolor --no-deps
pip install numpy opencv-python scikit-learn pillow matplotlib scipy
# Verify installation
python -c "import marearts_xcolor; print(marearts_xcolor.__version__)"This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Autpmatic Number Plate Recognition
- MareArts Reatime Video & Image Stiching
- MareArts Dominent Color Extraction
For questions or support:
- Email: hello@marearts.com
Made with β€οΈ by MareArts