U2Net 的背景去除太强了

Background removal with U2Net is too strong

我成功地使用 U2Net to remove the background of images using the terminal and I am also using the nice interface of this 存储库以更简单的方式做同样的事情并验证结果的相似性。但是,我的问题是背景去除对于这样的图像来说太强了:

我得到以下结果(即包装也被删除):

如果我在 Foco clipping website 和 select Type=='Graphic' 中上传图片,我会得到完全相同的结果。这意味着该网站正在使用相同的算法来删除图形类型图像的背景。不过,如果我 select Type=='Product',那么结果如下,这正是我想要的:

有没有人知道如何才能获得相同的结果?

  1. 你应该先锐化图像(使用强锐化)

from PIL import Image
from PIL import ImageFilter
from PIL.ImageFilter import (UnsharpMask)
simg = Image.open('data/srcimg07.jpg')
dimg = simg.filter(UnsharpMask(radius=4.5, percent=200, threshold=0))
dimg.save("result/ImageFilter_UnsharpMask_2_150_3.jpg")
  1. 使用U2Net去除锐化图像的背景

  1. 使用步骤(2)的结果作为mask

  1. 使用步骤 (3) 中的蒙版从原始图片中提取想要的结果

注意:这是一个非常简单的示例,您可以进一步完善它