中文 | English
A comprehensive Python toolkit for image color analysis, palette extraction, and visualization.
This toolkit contains 5 functional modules that form a complete color analysis pipeline:
| Tool | Function | Input | Output |
|---|---|---|---|
| Palette Generator | Generate color cards for each image | Image folder | Color palette images |
| Color Extractor | Analyze overall color distribution | Image folder | Color list + percentages |
| Co-occurrence Analyzer | Calculate color co-occurrence frequency | Image folder + color list | Frequency matrix |
| Network Viewer | Visualize color relationships | Color data + matrix | Network graph |
| Genetic Optimizer | Interactive color scheme optimization | Single image | Optimized color scheme |
┌─────────────────────────────────────────────────────────────────────────┐
│ Complete Analysis Pipeline │
└─────────────────────────────────────────────────────────────────────────┘
Step 1: Prepare Images
└── Put images to analyze in a folder
Step 2: Generate Palettes (Palette Generator)
├── Input: Image folder
├── Settings: Number of colors, gray threshold
└── Output: Color palette for each image (PNG)
Step 3: Extract Overall Colors (Color Extractor)
├── Input: Image folder
├── Process: K-Means clustering on all images
└── Output: Color list + percentages
e.g., [([255, 128, 64], 0.25), ([32, 64, 128], 0.18), ...]
Step 4: Calculate Co-occurrence (Co-occurrence Analyzer)
├── Input: Image folder + color list from Step 3
├── Process: Count which colors appear together
└── Output: N×N co-occurrence frequency matrix
Step 5: Visualize Network (Network Viewer)
├── Input: Color data + frequency matrix
└── Output: Color relationship network graph
- Nodes = Colors (size = percentage)
- Edges = Co-occurrence (red = strong correlation)
┌─────────────────────────────────────────────────────────────────────────┐
│ Genetic Algorithm Color Optimization │
└─────────────────────────────────────────────────────────────────────────┘
1. Open an image
2. System generates multiple color schemes (population)
3. Rate each scheme (0-10)
4. System evolves next generation based on ratings
5. Repeat 3-4 until satisfied
6. Export the best color scheme
<<<<<<< HEAD
# Clone the project
git clone https://github.com/yourusername/chromapath.git
=======
# 克隆项目
https://github.com/CodeSoul-co/Chromapath.git
>>>>>>> b7d46337a2a497d3ecc733bf7a1032cb3fbdfd1d
cd chromapath
# Create virtual environment (recommended)
conda create -n color python=3.10
conda activate color
# Install dependencies
pip install -r requirements.txt# Launch main interface
python main.py
# Or launch specific tool directly
python main.py --tool palette # Palette Generator
python main.py --tool extractor # Color Extractor
python main.py --tool cooccurrence # Co-occurrence Analyzer
python main.py --tool network # Network Viewer
python main.py --tool genetic # Genetic OptimizerPurpose: Batch generate color palettes for images
Steps:
- Select folder containing images
- Select output folder for palettes
- Set parameters:
- Gray Threshold: Filter near-gray pixels (default: 1)
- Number of Colors: Colors to extract per image (default: 8)
- Click "Generate Palettes"
Purpose: Analyze overall color distribution across multiple images
Steps:
- Select image folder
- Set number of colors (default: 18)
- Click "Analyze Images"
- View color distribution bar chart
- Copy color data at bottom (for next step)
Output Format:
[
([R, G, B], percentage),
([255, 128, 64], 0.2534),
...
]
Purpose: Analyze which colors frequently appear together
Steps:
- Select image folder
- Paste color data (from Color Extractor)
- Click "Analyze Co-occurrence"
- View co-occurrence frequency matrix
Matrix Interpretation:
matrix[i][j]= frequency of color i and j appearing together- Higher values indicate colors that often appear together
Purpose: Visualize color relationships as a network graph
Steps:
- Enter color data (format:
R G B Size)255 128 64 25 32 64 128 18 ... - Enter frequency matrix
- Set thresholds:
- Base Threshold: Minimum weight to show edge
- Highlight Threshold: Weight threshold for red highlight
- Click "Generate Network"
Purpose: Find optimal color schemes through interactive evolution
Steps:
- Click "Open Image" to select an image
- Set parameters:
- Colors: Number of colors in scheme
- Grid: Number of schemes per generation (rows × cols)
- Mutation: Mutation rate
- Elite Threshold: Score threshold for elite retention
- Rate each scheme using sliders (0-10)
- Click "Evolve Next Generation"
- Repeat rating and evolution until satisfied
- Click "Show Best" to view best scheme
from color_analyzer.core import ColorExtractor, CooccurrenceAnalyzer
from color_analyzer.visualization import ColorCardGenerator
import numpy as np
# Extract colors
extractor = ColorExtractor(n_colors=8, gray_threshold=1)
colors, percentages = extractor.extract_from_image("image.jpg")
# Generate color card
card_gen = ColorCardGenerator()
card_gen.save_card(colors, percentages, "palette.png")
# Analyze co-occurrence
analyzer = CooccurrenceAnalyzer(distance_threshold=10)
color_list = [np.array(c) for c in colors]
matrix = analyzer.analyze_folder("images/", color_list)
print(analyzer.format_matrix(matrix))chromapath/
├── main.py # Main entry point
├── requirements.txt # Dependencies
├── setup.py # Package setup
├── pyproject.toml # Modern Python packaging
├── README.md # Chinese documentation
├── README_EN.md # English documentation
├── LICENSE # MIT License
└── color_analyzer/ # Main package
├── __init__.py
├── core/ # Core algorithms
│ ├── image_processor.py # Image loading & preprocessing
│ ├── clustering.py # K-Means color clustering
│ ├── color_extractor.py # High-level color extraction
│ ├── cooccurrence.py # Co-occurrence analysis
│ └── genetic.py # Genetic algorithm
├── visualization/ # Visualization tools
│ ├── color_card.py # Color palette cards
│ └── network_plot.py # Network graphs
└── ui/ # PyQt5 GUI applications
├── main_window.py # Main launcher
├── palette_generator.py
├── color_extractor.py
├── cooccurrence_analyzer.py
├── network_viewer.py
└── genetic_optimizer.py
- Python 3.8+
- NumPy
- OpenCV (opencv-python)
- scikit-learn
- Matplotlib
- PyQt5
Contributions are welcome! Please feel free to submit a Pull Request.
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
