# ๐Ÿงน Background Removal Tool Advanced background removal for game assets with auto-detection and edge preservation. ## Features โœ… **Auto-detects background type** - White, Black, or Colored โœ… **Preserves cartoon outlines** - Uses edge detection to keep bold strokes โœ… **Smooth edges** - Applies subtle feathering to avoid jagged edges โœ… **Cleans artifacts** - Removes semi-transparent pixels and gray spots ## Usage ### Process single file: ```bash python3 scripts/remove_bg_advanced.py path/to/image.png ``` ### Process entire directory: ```bash python3 scripts/remove_bg_advanced.py assets/images/environment/ ``` ### Dry run (see what would be done): ```bash python3 scripts/remove_bg_advanced.py assets/images/ --dry-run ``` ### Non-recursive (only top-level files): ```bash python3 scripts/remove_bg_advanced.py assets/images/npcs/ --no-recursive ``` ## How It Works 1. **Detection**: Samples corner pixels to determine background color 2. **Edge Preservation**: Uses gradient detection to identify and preserve outlines 3. **Removal**: Creates alpha mask based on detected background 4. **Cleanup**: Applies feathering and removes semi-transparent artifacts ## Settings - **White backgrounds**: `tolerance=30` (removes light gray too) - **Black backgrounds**: `tolerance=60` (aggressive - removes dark gray) - **Colored backgrounds**: `tolerance=30` (samples from corners) - **Edge threshold**: `magnitude > 30` (lower = more edges preserved) - **Feathering**: `sigma=0.5` (smooth but not blurry) ## Examples **Before (white background)**: - Most, fence, building sprites **Before (black background)**: - Boss demons, dark effects, night scenes **After**: Clean transparent PNG with preserved cartoon outlines! ## Test Results โœ… Bridge (white bg) - Perfect removal โœ… Demon boss (black bg) - Clean removal without outline damage โœ… Automatic detection works on all asset types --- **Created for:** DolinaSmrti / NovaFarma Asset Pipeline