Giter Site home page Giter Site logo

Comments (4)

woctezuma avatar woctezuma commented on August 30, 2024 4

Just check the code. The gist of the algorithm is xuebinqin/U-2-Net.

img = Image.open(io.BytesIO(data)).convert("RGB")
mask = detect.predict(model, np.array(img)).convert("L")
if alpha_matting:
cutout = alpha_matting_cutout(
img,
mask,


  1. a segmentation mask is predicted with a neural network:

The first models (u2netp and u2net) are for salient object detection, and the other (u2net_human_seg) is for human segmentation.

'u2netp': (u2net.U2NETP,
'e4f636406ca4e2af789941e7f139ee2e',
'1rbSTGKAE-MTxBYHd-51l2hMOQPT_7EPy',
'U2NET_PATH'),
'u2net': (u2net.U2NET,
'09fb4e49b7f785c9f855baf94916840a',
'1ao1ovG1Qtx4b7EoskHXmi2E9rp5CHLcZ',
'U2NET_PATH'),
'u2net_human_seg': (u2net.U2NET,
'347c3d51b01528e5c6c071e3cff1cb55',
'1-Yg0cxgrNhHP-016FPdp902BR-kSsA4P',


  1. then alpha-matting cut-out is performed using:

def naive_cutout(img, mask):
empty = Image.new("RGBA", (img.size), 0)
cutout = Image.composite(img, empty, mask.resize(img.size, Image.LANCZOS))
return cutout

is_foreground = binary_erosion(is_foreground, structure=structure)
is_background = binary_erosion(is_background, structure=structure, border_value=1)

from pymatting.foreground.estimate_foreground_ml import estimate_foreground_ml


On a side-note, the README was updated 3 days ago (5cfa5bd) with a link to a little blogpost mentioning U2-Net, which was posted two days before the OP asked the question. So the information was already available through this other mean but not as easily available as it is now.


Finally, I will mention a competitor to U2-Net, which is MODNet. I don't know which performs better.

from backgroundremover.

TheJackiMonster avatar TheJackiMonster commented on August 30, 2024 1

I assume it scans the image for a human, segments the image in parts which are connected to the potentially moving human in the foreground and other parts will be the background via exclusion. Otherwise it would probably not work for animated backgrounds.

Another approach would be using an additional image source of the background only to help separating between background and foreground via differences to the background source. But because there is no such additional source given as parameter in the examples, that doesn't work here.

The most consistent way would probably be an additional input from a depth sensor/camera. So there wouldn't be the requirement of a human or specific object to be recognized in the foreground. However then you had bigger hardware limitations for users of the software. ^^'

from backgroundremover.

nadermx avatar nadermx commented on August 30, 2024 1

Thank you @woctezuma I will also add, that the video part, has a whimsical with a video made by https://github.com/ecsplendid whom is the developer who's code I modified to get it working on this, which all came from this issue in the rembg library

from backgroundremover.

nadermx avatar nadermx commented on August 30, 2024

@woctezuma I'll also put on the todo to be able to import in different models.

from backgroundremover.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.