|
@@ -37,17 +37,16 @@ Rembg is a tool to remove images background. That is it.
|
|
|
|
|
|
**If this project has helped you, please consider making a [donation](https://www.buymeacoffee.com/danielgatis).**
|
|
**If this project has helped you, please consider making a [donation](https://www.buymeacoffee.com/danielgatis).**
|
|
|
|
|
|
-
|
|
|
|
### Installation
|
|
### Installation
|
|
|
|
|
|
-#### **!! This library is for Python 3.9 only !!**
|
|
|
|
-
|
|
|
|
CPU support:
|
|
CPU support:
|
|
|
|
+
|
|
```bash
|
|
```bash
|
|
pip install rembg
|
|
pip install rembg
|
|
```
|
|
```
|
|
|
|
|
|
GPU support:
|
|
GPU support:
|
|
|
|
+
|
|
```bash
|
|
```bash
|
|
pip install rembg[gpu]
|
|
pip install rembg[gpu]
|
|
```
|
|
```
|
|
@@ -55,16 +54,19 @@ pip install rembg[gpu]
|
|
### Usage as a cli
|
|
### Usage as a cli
|
|
|
|
|
|
Remove the background from a remote image
|
|
Remove the background from a remote image
|
|
|
|
+
|
|
```bash
|
|
```bash
|
|
curl -s http://input.png | rembg i > output.png
|
|
curl -s http://input.png | rembg i > output.png
|
|
```
|
|
```
|
|
|
|
|
|
Remove the background from a local file
|
|
Remove the background from a local file
|
|
|
|
+
|
|
```bash
|
|
```bash
|
|
rembg i path/to/input.png path/to/output.png
|
|
rembg i path/to/input.png path/to/output.png
|
|
```
|
|
```
|
|
|
|
|
|
Remove the background from all images in a folder
|
|
Remove the background from all images in a folder
|
|
|
|
+
|
|
```bash
|
|
```bash
|
|
rembg p path/to/input path/to/output
|
|
rembg p path/to/input path/to/output
|
|
```
|
|
```
|
|
@@ -72,6 +74,7 @@ rembg p path/to/input path/to/output
|
|
### Usage as a server
|
|
### Usage as a server
|
|
|
|
|
|
Start the server
|
|
Start the server
|
|
|
|
+
|
|
```bash
|
|
```bash
|
|
rembg s
|
|
rembg s
|
|
```
|
|
```
|
|
@@ -83,26 +86,34 @@ http://localhost:5000/docs
|
|
```
|
|
```
|
|
|
|
|
|
Image with background:
|
|
Image with background:
|
|
|
|
+
|
|
```
|
|
```
|
|
https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg
|
|
https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg
|
|
```
|
|
```
|
|
|
|
|
|
Image without background:
|
|
Image without background:
|
|
|
|
+
|
|
```
|
|
```
|
|
http://localhost:5000/?url=https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg
|
|
http://localhost:5000/?url=https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg
|
|
```
|
|
```
|
|
|
|
|
|
Also you can send the file as a FormData (multipart/form-data):
|
|
Also you can send the file as a FormData (multipart/form-data):
|
|
|
|
+
|
|
```html
|
|
```html
|
|
-<form action="http://localhost:5000" method="post" enctype="multipart/form-data">
|
|
|
|
- <input type="file" name="file"/>
|
|
|
|
- <input type="submit" value="upload"/>
|
|
|
|
|
|
+<form
|
|
|
|
+ action="http://localhost:5000"
|
|
|
|
+ method="post"
|
|
|
|
+ enctype="multipart/form-data"
|
|
|
|
+>
|
|
|
|
+ <input type="file" name="file" />
|
|
|
|
+ <input type="submit" value="upload" />
|
|
</form>
|
|
</form>
|
|
```
|
|
```
|
|
|
|
|
|
### Usage as a library
|
|
### Usage as a library
|
|
|
|
|
|
Input and output as bytes
|
|
Input and output as bytes
|
|
|
|
+
|
|
```python
|
|
```python
|
|
from rembg import remove
|
|
from rembg import remove
|
|
|
|
|
|
@@ -117,6 +128,7 @@ with open(input_path, 'rb') as i:
|
|
```
|
|
```
|
|
|
|
|
|
Input and output as a PIL image
|
|
Input and output as a PIL image
|
|
|
|
+
|
|
```python
|
|
```python
|
|
from rembg import remove
|
|
from rembg import remove
|
|
from PIL import Image
|
|
from PIL import Image
|
|
@@ -130,6 +142,7 @@ output.save(output_path)
|
|
```
|
|
```
|
|
|
|
|
|
Input and output as a numpy array
|
|
Input and output as a numpy array
|
|
|
|
+
|
|
```python
|
|
```python
|
|
from rembg import remove
|
|
from rembg import remove
|
|
import cv2
|
|
import cv2
|
|
@@ -151,11 +164,13 @@ docker run -p 5000:5000 danielgatis/rembg s
|
|
```
|
|
```
|
|
|
|
|
|
Image with background:
|
|
Image with background:
|
|
|
|
+
|
|
```
|
|
```
|
|
https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg
|
|
https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg
|
|
```
|
|
```
|
|
|
|
|
|
Image without background:
|
|
Image without background:
|
|
|
|
+
|
|
```
|
|
```
|
|
http://localhost:5000/?url=https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg
|
|
http://localhost:5000/?url=https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg
|
|
```
|
|
```
|
|
@@ -166,10 +181,10 @@ All models are downloaded and saved in the user home folder in the `.u2net` dire
|
|
|
|
|
|
The available models are:
|
|
The available models are:
|
|
|
|
|
|
-- u2net ([download](https://drive.google.com/uc?id=1tCU5MM1LhRgGou5OpmpjBQbSrYIUoYab), [source](https://github.com/xuebinqin/U-2-Net)): A pre-trained model for general use cases.
|
|
|
|
-- u2netp ([download](https://drive.google.com/uc?id=1tNuFmLv0TSNDjYIkjEdeH1IWKQdUA4HR), [source](https://github.com/xuebinqin/U-2-Net)): A lightweight version of u2net model.
|
|
|
|
-- u2net_human_seg ([download](https://drive.google.com/uc?id=1ZfqwVxu-1XWC1xU1GHIP-FM_Knd_AX5j), [source](https://github.com/xuebinqin/U-2-Net)): A pre-trained model for human segmentation.
|
|
|
|
-- u2net_cloth_seg ([download](https://drive.google.com/uc?id=15rKbQSXQzrKCQurUjZFg8HqzZad8bcyz), [source](https://github.com/levindabhi/cloth-segmentation)): A pre-trained model for Cloths Parsing from human portrait. Here clothes are parsed into 3 category: Upper body, Lower body and Full body.
|
|
|
|
|
|
+- u2net ([download](https://drive.google.com/uc?id=1tCU5MM1LhRgGou5OpmpjBQbSrYIUoYab), [source](https://github.com/xuebinqin/U-2-Net)): A pre-trained model for general use cases.
|
|
|
|
+- u2netp ([download](https://drive.google.com/uc?id=1tNuFmLv0TSNDjYIkjEdeH1IWKQdUA4HR), [source](https://github.com/xuebinqin/U-2-Net)): A lightweight version of u2net model.
|
|
|
|
+- u2net_human_seg ([download](https://drive.google.com/uc?id=1ZfqwVxu-1XWC1xU1GHIP-FM_Knd_AX5j), [source](https://github.com/xuebinqin/U-2-Net)): A pre-trained model for human segmentation.
|
|
|
|
+- u2net_cloth_seg ([download](https://drive.google.com/uc?id=15rKbQSXQzrKCQurUjZFg8HqzZad8bcyz), [source](https://github.com/levindabhi/cloth-segmentation)): A pre-trained model for Cloths Parsing from human portrait. Here clothes are parsed into 3 category: Upper body, Lower body and Full body.
|
|
|
|
|
|
#### How to train your own model
|
|
#### How to train your own model
|
|
|
|
|
|
@@ -179,6 +194,7 @@ https://github.com/danielgatis/rembg/issues/193#issuecomment-1055534289
|
|
### Advance usage
|
|
### Advance usage
|
|
|
|
|
|
Sometimes it is possible to achieve better results by turning on alpha matting. Example:
|
|
Sometimes it is possible to achieve better results by turning on alpha matting. Example:
|
|
|
|
+
|
|
```bash
|
|
```bash
|
|
curl -s http://input.png | rembg i -a -ae 15 > output.png
|
|
curl -s http://input.png | rembg i -a -ae 15 > output.png
|
|
```
|
|
```
|
|
@@ -206,11 +222,12 @@ Please contact me at [email protected] if you need help to put it on the clo
|
|
|
|
|
|
### References
|
|
### References
|
|
|
|
|
|
-- https://arxiv.org/pdf/2005.09007.pdf
|
|
|
|
-- https://github.com/NathanUA/U-2-Net
|
|
|
|
-- https://github.com/pymatting/pymatting
|
|
|
|
|
|
+- https://arxiv.org/pdf/2005.09007.pdf
|
|
|
|
+- https://github.com/NathanUA/U-2-Net
|
|
|
|
+- https://github.com/pymatting/pymatting
|
|
|
|
|
|
### Buy me a coffee
|
|
### Buy me a coffee
|
|
|
|
+
|
|
Liked some of my work? Buy me a coffee (or more likely a beer)
|
|
Liked some of my work? Buy me a coffee (or more likely a beer)
|
|
|
|
|
|
<a href="https://www.buymeacoffee.com/danielgatis" target="_blank"><img src="https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;"></a>
|
|
<a href="https://www.buymeacoffee.com/danielgatis" target="_blank"><img src="https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;"></a>
|