Who said to be PS? This open-source artifact can also be pulled in batch, and the effect is outstanding!

Time:2021-7-30

[introduction]: an open source tool that can be used to quickly remove background pictures. After installation and configuration, you can batch operate pictures on the server and command line.

brief introduction

Rembg is a tool implemented in Python for removing background images. It requires Python version 3.8 or higher. It supports batch operations. It can be used flexibly. It can be used directly on the command line, as a service, in docker, or as a library call.

Download and install

The source code address of the project is:

https://github.com/danielgati…

Python 3.8 or later is required to install using the following command:

pip install rembg

Simple use

1. Use in the command line

In the command line, you can operate the server pictures, local pictures and the whole folder pictures, as follows:

(1) Operate on remote pictures:

curl -s http://input.png | rembg > output.png

(2) Operate on local pictures:

rembg -o path/to/output.png path/to/input.png

(3) Operate the pictures in the whole folder:

rembg -p path/to/inputs

2. Use as a service

(1) Start service

rembg-server

(2) If the picture can be accessed by direct link, you can directly open the following address through the browser:

http://localhost:5000?url=http://image.png

You can also use HTML forms to upload files:

<form action="http://localhost:5000" method="post" enctype="multipart/form-data">
    <input type="file" name="file"/>
    <input type="submit" value="upload"/>
 </form>

3. Use in docker

It is also convenient to use in docker. Run the following commands directly:

curl -s http://input.png | docker run -i -v ~/.u2net:/root/.u2net danielgatis/rembg:latest > output.png

4. Call as library

It’s also easy to call directly in the script. First create app.py, as follows:

import sys
from rembg.bg import remove
sys.stdout.buffer.write(remove(sys.stdin.buffer.read()))

Then execute the command to run:

cat input.png | python app.py > out.png

Project sample usage effect:

Who said to be PS? This open-source artifact can also be pulled in batch, and the effect is outstanding!

Advanced use

Some pictures may be processed in alpha matching mode (i.e. using – A – AE 15 option), and the effect will be more perfect. The command is as follows:

curl -s http://input.png | rembg -a -ae 15 > output.png

The effect comparison diagram is as follows:

Who said to be PS? This open-source artifact can also be pulled in batch, and the effect is outstanding!

epilogue

That’s all for the brief introduction of remgb. Interested children’s shoes can be downloaded and installed in person. For more details, see the project home page.

Open source outpostShare popular, interesting and practical open source projects on a daily basis. Participate in maintaining the open source technology resource library of 100000 + star, including python, Java, C / C + +, go, JS, CSS, node.js, PHP,. Net, etc.