lizhihao6 / Forward-Warp

An optical flow forward warp's lib with backpropagation using pytorch.
MIT License
109 stars 17 forks source link

N-to-1 mapping #10

Closed askerlee closed 2 years ago

askerlee commented 2 years ago

Hi @lizhihao6 , first thank you for this great repo. I just began to use it and found the forward-warpped image seems to contain some large values. After checking the python implementation it seems that it simply accumulates all the pixel values mapped to each pixel? It's common that mulitple source pixels can be forward-mapped to the same target pixel. In that case, a weighted average (instead of adding them all up) seems to be more reasonable? But in order to do that, we have to keep counting the (fractional) counts of source pixels that are mapped to each target pixel. Thanks.

lizhihao6 commented 2 years ago

Hi @askerlee, thanks for your attention. The problem you describe does exist, and in fact the official implemented backward warp by pytorch has the same issue (at least in pytorch==1.0). So you could solve this by counting pixels for example warp a white image (torch.ones_like(x)). If you still have any question, please feel free to ask me.

askerlee commented 2 years ago

Thank you! This is a smart solution. I was thinking to revise your code and add counting, but apparently that would be quite time consuming. Now your workaround saved my day! 😄