Add PNG to SVG color separation tool for multi-color 3D printing

Created split_png_by_brightness.py to split rasterized logos into separate
SVG files by color for Underground Magnetics logo conversion.

Key features:
- OpenCV contour hierarchy detection for proper hole handling
- Letters with enclosed shapes (d, o, g, etc.) now render correctly
- Tight brightness thresholds to avoid antialiasing artifacts
- Automatic bounding box cropping for optimal file sizes
- Black text: brightness < 40 (236k pixels, 21 shape groups)
- Grey icon: brightness 108-118 (119k pixels, 2 shape groups)

Results:
- um_black.svg: 6.1KB, 3070x233px (was 139KB, 3613x391px)
- um_grey.svg: 728B, 413x390px (was 253KB, 3613x391px)

Files:
- split_png_by_brightness.py: Main color separation tool
- IMPROVEMENTS.md: Detailed changelog and comparison
- README_underground_magnetics.md: Usage documentation
- underground-magnetics.eps: Source logo file
- um_black.svg: Separated black text (cropped)
- um_grey.svg: Separated grey icon (cropped)
- requirements.txt: Added opencv-python dependency

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-05-31 09:51:24 -05:00
parent 8b80f68a19
commit 2719ec244d
7 changed files with 423 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
# Underground Magnetics Logo - Color Separation
Successfully split the Underground Magnetics EPS logo into separate SVG files by color for multi-color 3D printing.
## Process
1. **EPS to PNG Conversion**: Used ImageMagick to convert `underground-magnetics.eps` to PNG format
- Output: `underground-magnetics-0.png` and `underground-magnetics-1.png`
2. **Color Separation**: Used `split_png_by_brightness.py` to extract separate colors
- Analyzed brightness values to distinguish grey icon from black text
- Created separate SVG files for each color region
## Output Files
- **underground-magnetics_grey.svg** - Grey "UM" icon (126,801 pixels, 1609 paths)
- **underground-magnetics_black.svg** - Black "Underground Magnetics" text (237,130 pixels, 27 paths)
## Usage
To convert these SVG files to 3D models for multi-color printing:
```bash
# Convert grey icon to STL
python svg_logo_to_stl.py underground-magnetics_grey.svg um_grey --width-mm 100 --base-thickness 1.5 --feature-height 2.5
# Convert black text to STL
python svg_logo_to_stl.py underground-magnetics_black.svg um_black --width-mm 100 --base-thickness 1.5 --feature-height 2.5
```
## Tools Created
### split_png_by_brightness.py
Splits PNG images into separate SVG files based on brightness/color clusters.
**Usage:**
```bash
python split_png_by_brightness.py <input.png> [options]
Options:
--output-dir, -o Output directory (default: same as input)
--prefix, -p Prefix for output files (default: input filename)
--dark-threshold INT Brightness threshold for dark/black (default: 50)
--mid-threshold INT Brightness threshold for mid/grey (default: 150)
```
**Example:**
```bash
python split_png_by_brightness.py underground-magnetics-0.png --prefix underground-magnetics
```
This creates separate SVG files for each color region detected in the PNG.
## Color Detection
The script analyzes pixel brightness to separate colors:
- **Dark pixels** (brightness < 50): Black text → `_black.svg`
- **Mid-range pixels** (50 ≤ brightness < 150): Grey icon → `_grey.svg`
- **Light pixels** (brightness ≥ 150): White background (ignored)
## Next Steps
1. Import the separate SVG files into the 3D conversion tool
2. Generate STL files for each color
3. Create 3MF assembly with multiple selectable parts
4. Import into BambuStudio for multi-color printing