#!/usr/bin/env python3 """ AI Background Removal using rembg This will properly remove ANY background and create clean alpha transparency """ import os import shutil from pathlib import Path from rembg import remove from PIL import Image # Test images TEST_IMAGES = [ "assets/PHASE_PACKS/1_FAZA_1/tools/wood/watering_can.png", "assets/PHASE_PACKS/1_FAZA_1/animals/horse.png", "assets/PHASE_PACKS/1_FAZA_1/infrastructure/farm_elements/manure_pile.png", "assets/PHASE_PACKS/1_FAZA_1/tools/iron/pickaxe.png", "assets/PHASE_PACKS/1_FAZA_1/animals/sheep/walk.png", ] OUTPUT_DIR = "test_transparency" def ai_remove_bg(input_path, output_path): """Use AI (rembg) to remove background""" img = Image.open(input_path) # Remove background using AI result = remove(img) result.save(output_path, 'PNG') print(f" ✅ AI Processed: {os.path.basename(output_path)}") def main(): print("🤖 AI BACKGROUND REMOVAL (rembg)") print("=" * 50) print("\nUsing neural network to detect and remove backgrounds\n") os.makedirs(OUTPUT_DIR, exist_ok=True) processed = [] for img_path in TEST_IMAGES: if not os.path.exists(img_path): print(f" ❌ Not found: {img_path}") continue name = os.path.basename(img_path) name_no_ext = os.path.splitext(name)[0] # AI process ai_dest = os.path.join(OUTPUT_DIR, f"{name_no_ext}_AI.png") ai_remove_bg(img_path, ai_dest) processed.append({ 'name': name_no_ext, 'original': f"{name_no_ext}_ORIGINAL.png", 'ai': f"{name_no_ext}_AI.png" }) # Generate comparison HTML html = '''