Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results without fringe #75

Closed
danielgatis opened this issue Sep 29, 2020 · 10 comments
Closed

Results without fringe #75

danielgatis opened this issue Sep 29, 2020 · 10 comments

Comments

@danielgatis
Copy link

Hi @Nathanua,

I have a library that makes use of your model.

@alfonsmartinez opened an issue about the model result, please, take a look at here:
danielgatis/rembg#14

Can you figure out how I can achieve this result without the black fringe?

thanks.

@kashyappiyush1998
Copy link

In my case, this is green edges with green screen

@xuebinqin
Copy link
Owner

xuebinqin commented Oct 3, 2020 via email

@kashyappiyush1998
Copy link

But I want to make a general case model which works on both monotonous and complex background, If I dilate on images that already show good results, wouldn't it cut off my borders.

@kashyappiyush1998
Copy link

kashyappiyush1998 commented Oct 6, 2020

hkchengrex/CascadePSP#25
Results using Cascade PSP are not good either, as well as processing time skyrockets.

@99991
Copy link

99991 commented Oct 8, 2020

It might help to create a trimap from the U-2-Net mask by erosion and dilation. The image and trimap can then be used as input for some alpha matting framework.

But even with a hand-drawn trimap, the result will not perfect because there is some blue chromatic aberration on the rice grains (most noticeable on the top right).

grid

@danielgatis
Copy link
Author

Hi thomas @99991

It might help to create a trimap from the U-2-Net mask by erosion and dilation.

Sorry for the dumb question but can you provide the code that generates the trimap in this example?

@99991
Copy link

99991 commented Oct 9, 2020

@danielgatis That trimap was hand-drawn, but it is not too difficult to generate it automatically from the output of u2net. Simply threshold the prediction to get approximate foreground and background masks, erode the masks to increase the region where alpha matting methods are allowed to calculate the alpha values and then combine the masks to form a trimap.

Here is some code to do this.

I reduced the size of the input image to not run out of memory.

A solution for a less memory hungry method for alpha matting is described in this paper

There is also this paper, where the authors predict an alpha matte directly from the input image without trimap, but the associated repository has no code at the moment and it would probably not be legal to use the network due to the license of the images it was trained on.

@kashyappiyush1998
Copy link

Matting Still does not remove the edges,
record-a-green-screen-video-9f3a2a27-6cda-4327-a050-7ec5aa3e87dfImage_EHFPA50H
I have uploaded a small resized image, on original 1920X1080 green edges are clearly visible

@99991
Copy link

99991 commented Oct 9, 2020

@kashyappiyush1998 Maybe you are not doing foreground estimation or your alpha matte is too large for some reason. It should also work with green backgrounds.

See for example this image from https://commons.wikimedia.org/wiki/File:Girl_in_front_of_a_green_background.jpg (licensed under Creative Commons Attribution 2.0 Generic license by User "PictureYouth"). This image is somewhat challenging because there is color spill on the shirt due to reflections from the background and yet it works reasonably well even though u2net does not detect the pants correctly.

cutout

(Generated with this hacky code, just for testing, not production ready)

@danielgatis
Copy link
Author

danielgatis commented Oct 9, 2020

Hi @kashyappiyush1998,

I have a project that just pipes the u2net output to the pymatting and I got the following results:

curl -s https://upload.wikimedia.org/wikipedia/commons/c/c2/Girl_in_front_of_a_green_background.jpg | rembg -a > a.png

a

curl -s https://user-images.githubusercontent.com/35548940/95571670-6f866800-0a46-11eb-9a7c-8272e0229ee6.jpg | rembg -a > b.png

b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants