A powerful command-line tool for automatically coloring UV islands in UV unwrap maps. Each UV island gets a unique color with maximized contrast between neighboring islands.
- Fast Mode: Uses SciPy for quick processing (original implementation)
- Complex Mode: Precise BFS algorithm with detailed control
- OpenCV Mode: Optimized with OpenCV for maximum performance
- Skimage Mode: Uses scikit-image for advanced image processing
- With Alpha: PNG, TGA, TIFF, WebP, etc.
- Without Alpha: JPEG, BMP, PPM, etc. (automatic alpha generation)
- Batch Processing: Process entire folders of images
- Pure Colors First: Maximize contrast between islands
- Blended Colors: When many islands need distinct colors
- Automatic Detection: Works with or without alpha channels
- Border Control: Adjustable border expansion with fade options
- Vectorized Operations: NumPy-based for speed
- Parallel Processing: Multi-core support where available
- Memory Efficient: Handles large images smoothly
# Install all dependencies
python install.py all
# Or install specific mode
python install.py opencv # Fastest mode
python install.py fast # Original fast mode
python install.py minimal # Minimal dependencies only
# Install core dependencies
pip install Pillow numpy
# For fast mode
pip install scipy
# For opencv mode (fastest)
pip install opencv-python
# For skimage mode
pip install scikit-image
# Or install everything at once
pip install Pillow numpy scipy opencv-python scikit-image
- Windows: If OpenCV installation fails, try opencv-python-headless
- Mac/Linux: Should work out of the box with pip
- Python Version: Python 3.8 or higher required
# Single image processing
python UVIslandColorizer.py input.png output.png
# With specific mode
python UVIslandColorizer.py input.tga output.png --mode opencv
python UVIslandColorizer.py input.jpg output.png --mode fast
python UVIslandColorizer.py input.png output.png --mode complex
# Process entire folder
python UVIslandColorizer.py input_folder output_folder --batch --mode fast
Positional Arguments:
input Input image file or directory
output Output image file or directory
Processing Modes:
--mode {fast,complex,opencv,skimage}
Processing mode (default: fast)
Alpha Channel Settings:
--threshold FLOAT Alpha threshold for images with alpha (0.0-1.0, default: 0.1)
--solid-threshold FLOAT
Brightness threshold for images without alpha (0.0-1.0, default: 0.9)
--invert-mask Invert mask for images without alpha (default: dark=transparent)
Border Processing:
--border-scale FLOAT Border scale (0.0-2.0, default: 0.1)
--fade-alpha Fade alpha at borders (default: sharp edges)
Color Settings:
--blended-only Use only blended colors (default: pure colors first)
Batch Processing:
--batch Batch process all images in input directory
Help:
--help Show help message and exit
# TGA with alpha channel
python UVIslandColorizer.py "T_SM_BuddhaHead_MM_OpaqueSimple_Inst_C.TGA" result.png --mode opencv
# JPEG without alpha (automatic detection)
python UVIslandColorizer.py texture.jpg result.png --solid-threshold 0.8
# Inverted mask for light-on-dark textures
python UVIslandColorizer.py texture.jpg result.png --solid-threshold 0.8 --invert-mask
# Sharp borders (no fade)
python UVIslandColorizer.py input.png output.png --border-scale 0.1
# Faded borders
python UVIslandColorizer.py input.png output.png --border-scale 0.2 --fade-alpha
# No border expansion
python UVIslandColorizer.py input.png output.png --border-scale 0.0
# Pure colors only (best contrast)
python UVIslandColorizer.py input.png output.png --mode fast
# Blended colors only (when many islands)
python UVIslandColorizer.py input.png output.png --blended-only
# Complex mode with custom search range
python UVIslandColorizer.py input.png output.png --mode complex --border-scale 0.5
- UV Island Detection
- Alpha-based: Uses alpha channel threshold for transparent background
- Brightness-based: For images without alpha, uses brightness threshold
- Connectivity: 8-connected component analysis to find islands
- Color Generation
- Pure Colors: Generated in HSV space for maximum contrast
- Blended Colors: Created by mixing base colors when needed
- Contrast Optimization: Colors are spaced to maximize distinction
- Border Processing
- Edge Detection: Finds boundaries between islands and background
- Border Expansion: Controlled by --border-scale parameter
- Alpha Fading: Optional smooth transitions at edges
- Performance Optimization
- Vectorization: NumPy operations instead of Python loops
- Library Acceleration: Uses optimized libraries when available
- Memory Mapping: Efficient handling of large images
| Mode | Speed | Memory | Dependencies | Best For |
|---|---|---|---|---|
| OpenCV | βββββ | Low | OpenCV | Large images, batch processing |
| Fast | ββββ | Medium | SciPy | Balanced performance |
| Skimage | βββ | Medium | scikit-image | Advanced operations |
| Complex | ββ | High | None | Precision, small images |
- Game Development
- UV map visualization for 3D models
- Texture atlas debugging
- Material assignment previews
- 3D Modeling
- UV layout analysis
- Island identification
- Texture painting preparation
- Research & Education
- Computer graphics teaching
- Image processing research
- Algorithm visualization
- OpenCV fails to load TGA files
- Solution: Tool automatically falls back to PIL for TGA support
- Memory issues with large images
- Solution: Use OpenCV mode, reduce border scale
- Poor results with images without alpha
- Solution: Adjust --solid-threshold and try --invert-mask
- Slow processing on large folders
- Solution: Use --mode opencv for batch processing
- "SciPy not available": Install with pip install scipy or use --mode complex
- "OpenCV not available": Install with pip install opencv-python or use another mode
- "Image loading failed": Check file format and permissions
- Customizing Color Generation
- The tool uses HSV color space for optimal contrast. You can modify the generate_colors method in the source code to implement custom color schemes.
- Extending for Specific Formats
- To add support for additional image formats, modify the load_image_safe function in UVIslandColorizer.py.
- Integration with Pipelines
- The tool can be integrated into automated pipelines:
# Example pipeline integration
find . -name "*.tga" -exec python UVIslandColorizer.py {} {}.colored.png \;
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- Inspired by HLSL shader code for UV island coloring
- Built with Pillow, NumPy, SciPy, OpenCV, and scikit-image
- Thanks to all contributors and testers
- Issues: Use the GitHub issue tracker
- Questions: Check the examples above or open an issue
- Feature Requests: Submit via GitHub issues