Does the paper provide a justification for increasing the gradient contribution? If so, it would be helpful to add a comment with the justification (personally, I'd prefer it where the factor is specified, as opposed to here, but either way is probably fine).

What's confusing though is that this factor is applied selectively. The `0.5` makes sense mathematically, since the gradient should be multiplied by one over the step size and `factor` is only used below when the pixel distance is 2. But if the point is to weight the gradient, why is that weight applied selectively to the case when the both neighbors are known. If there's could be a good reason, but it should be documented so that someone reading the code doesn't think it's a bug.