rembg - Rembgは、画像の背景を削除するツールです。

(Rembg is a tool to remove images background.)

Created at: 2020-08-10 22:38:24
Language: Python
License: MIT

レンブ

ダウンロード ダウンロード ダウンロード ライセンス ハグフェイススペース

Rembgは、画像の背景を削除するツールです。あれだ。

このプロジェクトが役に立った場合は、寄付を検討してください。

必要条件

python: >3.7, <3.11

取り付け

CPUサポート:

pip install rembg

GPU のサポート:

pip install rembg[gpu]

CLI としての使用

リモートイメージから背景を削除する

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

ローカルファイルから背景を削除する

rembg i path/to/input.png path/to/output.png

フォルダ内のすべての画像から背景を削除する

rembg p path/to/input path/to/output

サーバーとしての利用

サーバーの起動

rembg s

そして、次の場所に移動します。

http://localhost:5000/docs

背景付き画像:

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

また、ファイルをフォームデータ(マルチパート/フォームデータ)として送信することもできます。

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

ライブラリとしての利用

バイト単位の入力と出力

from rembg import remove

input_path = 'input.png'
output_path = 'output.png'

with open(input_path, 'rb') as i:
    with open(output_path, 'wb') as o:
        input = i.read()
        output = remove(input)
        o.write(output)

PIL画像として入出力

from rembg import remove
from PIL import Image

input_path = 'input.png'
output_path = 'output.png'

input = Image.open(input_path)
output = remove(input)
output.save(output_path)

Input and output as a numpy array

from rembg import remove
import cv2

input_path = 'input.png'
output_path = 'output.png'

input = cv2.imread(input_path)
output = remove(input)
cv2.imwrite(output_path, output)

Usage as a docker

Try this:

docker run -p 5000:5000 danielgatis/rembg s

Image with background:

https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Gull_portrait_ca_usa.jpg/1280px-Gull_portrait_ca_usa.jpg

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

Models

All models are downloaded and saved in the user home folder in the directory.

.u2net

The available models are:

  • u2net (download, source): A pre-trained model for general use cases.
  • u2netp (download, source): A lightweight version of u2net model.
  • u2net_human_seg (download, source): A pre-trained model for human segmentation.
  • u2net_cloth_seg (download, source): 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

If You need more fine tunned models try this: https://github.com/danielgatis/rembg/issues/193#issuecomment-1055534289

Advance usage

アルファマットをオンにすることで、より良い結果が得られる場合があります。例:

curl -s http://input.png | rembg i -a -ae 15 > output.png
翻訳元 アルファマットなし アルファマット付き (-a -ae 15)

クラウド内

クラウドに置くのに助けが必要な場合は、danielgatis@gmail.comで私に連絡してください。

参照

コーヒーを買って

私の仕事のいくつかが好きでしたか?コーヒー(またはおそらくビール)を買ってください

コーヒーを買って

ライセンス

著作権(c)2020-現在ダニエルガティス

MITライセンスの下でライセンスされています