🖼️ Image Background & Foreground Removal Tool This Python application allows users to remove the background or foreground of an image using a deep learning model. After removing the background, you can replace it with any color of your choice — perfect for generating clean, professional-looking images!
✨ Features 🔍 Automatically removes background from input images.
🎯 Optional foreground removal for isolating the background.
🎨 Allows custom background color replacement (e.g., white, green, blue, etc.).
🤖 Uses a pre-trained Keras/TensorFlow segmentation model (model.h5).
📂 Processes single images or batches from a folder.
🧠 Supports custom metrics like Dice Loss, IoU, and Dice Coefficient.
🛠️ Tech Stack Python 3.x
TensorFlow / Keras
NumPy
OpenCV (cv2)
tqdm
📁 Folder Structure graphql Copy Edit image-background-removal/ ├── model.h5 # Trained segmentation model ├── run.py # Main script to process images ├── metrics.py # Custom metrics (dice_loss, dice_coef, iou) ├── input/ # Input images ├── output/ # Output images (after processing) ├── README.md 📦 Installation bash Copy Edit git clone https://github.com/Ramteja24/Image-Background-Removal-AI.git cd image-background-removal
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt ✅ Usage Run the script:
bash Copy Edit python run.py --input input/image.jpg --bg_color white You can also specify a hex color:
bash Copy Edit python run.py --input input/photo.png --bg_color "#00ff00" 🧠 Custom Model Metrics In metrics.py:
python Copy Edit def dice_loss(y_true, y_pred): ... def dice_coef(y_true, y_pred): ... def iou(y_true, y_pred): ... These metrics are automatically passed via custom_objects while loading the model.
🖌️ Custom Background Color You can choose any color to replace the removed background:
Common options: white, black, green, blue, etc.
Or use custom hex codes like #ffcc00.

