Home > Software engineering >  Background removal with U2Net is too strong
Background removal with U2Net is too strong

Time:09-22

I am successfully using enter image description here

Where I get the following result (i.e. packaging is also removed):

enter image description here

If I upload the image in enter image description here

Does anyone have any idea on what to do to obtain the same result?

CodePudding user response:

  1. you should sharpen the image first (use strong sharpen)

Example

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. use U2Net to remove the background of the sharpened image

Example

  1. use the result from step (2) as mask

Example

  1. using the mask from step (3) extract wanted result from original picture

Example

note: this is very quick example, you could refine it more

  • Related