danielgatis / rembg

Rembg is a tool to remove images background
MIT License
16.72k stars 1.86k forks source link

why? www.remove.bg is good, but Using PIL is bad #140

Closed xiaoyezi55 closed 3 years ago

xiaoyezi55 commented 3 years ago
  1. by: https://www.remove.bg/zh/upload

input.png: imput_test1

out.png is good! imput_test1-removebg-preview

  1. by: Using PIL from rembg.bg import remove import numpy as np import io from PIL import Image

input_path = 'input.png' output_path = 'out.png'

f = np.fromfile(input_path) result = remove(f) img = Image.open(io.BytesIO(result)).convert("RGBA") img.save(output_path)

input.png: imput_test1

out.png is bad! output1

ggua5470 commented 3 years ago

Just my opinion.

https://www.remove.bg/ is a commercial product, so I believe it pre-analyzes your input image first to provide better results for different type of input. If it finds your image has a border of background of a plain color, it may just use simple algorithm or chromakey (greenscreen) to remove the background. If the input is a more generic type of image, it uses their in-house AI algorithms to detect the background.

For Rembg, it uses https://github.com/xuebinqin/U-2-Net, which is a "Salient Object Detection" AI. So it handles well with generic photos, but not suitable for some other types of images, in this case a computer-generated pattern image with a border.

xiaoyezi55 commented 3 years ago

My image has a border of background of a plain color, Can you recommend some simple algorithms to remove the background?

ggua5470 commented 3 years ago

If you are using python, you should just read the image and crop it based on you border color. A quick google search gives the below, it is easy enough to customize it for your need. https://www.programmerall.com/article/47791850168/

xiaoyezi55 commented 3 years ago

Thanks very much

cclauss commented 3 years ago

Can this issue be closed or is there a TODO here?

danielgatis commented 3 years ago

closed. no TODO.