A newer version of the Gradio SDK is available:
5.24.0
title: Free Background Remover
emoji: π
colorFrom: green
colorTo: green
sdk: gradio
sdk_version: 4.41.0
app_file: app.py
pinned: false
license: apache-2.0
Advanced Background Remover v2.2
This project is a web-based tool for removing the background from images. It provides users with several advanced options such as background color replacement, model selection, alpha matting, and more, using the rembg
library.
Features
- Background Removal: Automatically remove the background from images.
- Model Selection: Choose from a variety of pre-trained models for different use cases, including general use, human segmentation, and anime character segmentation.
- Custom Background Color: Replace the removed background with a custom color.
- Alpha Matting: Improve the quality of the background removal with alpha matting.
- Post-Processing: Option to post-process the mask for better results.
- Only Mask: Option to return only the mask of the image without any background.
Pre-Trained Models
The following models are available for selection:
- u2net: A pre-trained model for general use cases.
- u2netp: A lightweight version of the u2net model.
- u2net_human_seg: A pre-trained model for human segmentation.
- u2net_cloth_seg: A pre-trained model for cloth parsing from human portraits.
- silueta: Same as u2net but with a reduced size.
- isnet-general-use: A new pre-trained model for general use cases.
- isnet-anime: High-accuracy segmentation for anime characters.
- sam: A pre-trained model for any use cases.
Installation
Clone this repository:
git clone https://github.com/your-username/background-remover.git cd background-remover
Install the required dependencies:
pip install -r requirements.txt
Run the application:
python app.py
Usage
- Upload an image by dragging it into the upload area.
- (Optional) Select a background color using the color picker.
- Choose a model from the dropdown menu.
- Enable or disable alpha matting and post-processing options as needed.
- Click "Submit" to remove the background.
- View the processed image directly on the page.
- Download the processed image by clicking on the download link.
Configuration
You can customize the project by editing the app.py
file, which includes the following key options:
- Model Selection: Adjust the models available for users.
- Alpha Matting: Modify the parameters for alpha matting.
- Post-Processing: Enable or disable post-processing of the mask.
Example
Here's a simple example of how to use the remove function:
from PIL import Image
from rembg import remove
input_image = Image.open('input.png')
output_image = remove(input_image, alpha_matting=True, alpha_matting_foreground_threshold=270, alpha_matting_background_threshold=20, alpha_matting_erode_size=11)
output_image.save('output.png')
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
- rembg - The Python library used for background removal.
- Gradio - The framework used to create the user interface.
Readme generated by chatgpt