1 | initial version |
I would add another answer.
Get the mean direction in a sliding window: make a 2x2 matrix containing:
[ Sum(Gx²) Sum(GxGy) ]
[ Sum(GxGy) Sum(Gy²) ]
Compute the PCA of this matrix. The first eigenvector will give you the mean gradient direction.