Yaoyi-Li / GCA-Matting

Official repository for Natural Image Matting via Guided Contextual Attention
MIT License
390 stars 62 forks source link

compose two fg maybe has one error ? #12

Open hengshan123 opened 4 years ago

hengshan123 commented 4 years ago

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

Yaoyi-Li commented 4 years ago

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.