I check your code and see that you + 1 for intersection width and height. I think you want to avoid zero division error, but it leads to a significant shift if I measure the results at different scales (image resolution).
I think we should replace 1 with a very small number such as 1e-6
See Issue #153