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

compose two fg maybe has one error ? #12

Open
hengshan123 opened this issue Aug 4, 2020 · 1 comment
Open

compose two fg maybe has one error ? #12

hengshan123 opened this issue Aug 4, 2020 · 1 comment

Comments

@hengshan123
Copy link

in dataloader/data_gernerator.py _composite_fg function
alpha_tmp = 1 - (1 - alpha) * (1 - alpha2)
fg = fg.astype(np.float32) * alpha[:,:,None] + fg2.astype(np.float32) * (1 - alpha[:,:,None])
when compute new fg, the fg2 multiple (1-alpha) , but should fg2 muliple (1-alpha2) ?

https://github.com/Yaoyi-Li/GCA-Matting/blob/master/dataloader/data_generator.py#L520

@hengshan123 hengshan123 changed the title compose two fg maybe has one error compose two fg maybe has one error ? Aug 5, 2020
@Yaoyi-Li
Copy link
Owner

Yaoyi-Li commented Aug 7, 2020

Hi, thanks for your interest.

There are many feasible ways to merge two foreground images and a background together. Here, we see fg2 as a background image, and we composite fg and fg2 for a new foreground image by coefficients alpha and (1-alpha). alpha_tmp is a synthesized and acceptable alpha image. If the coefficients are alpha and (1-alpha2), it is not a convex combination and might overflow.

If you want the merging to be more reasonable, you can let fg = alpha1*(1-alpha2)/(1-(1-alpha1)*(1-alpha2))fg1 + alpha2/(1-(1-alpha1)(1-alpha2))*fg2, and still alpha = 1 - (1 - alpha) * (1 - alpha2). It means you merge fg1 with bg by alpha1 first, and then merge fg2 with the composition by alpha2.

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

2 participants