Search code examples
matlabgradienthough-transform

find the gradient direction at a point in a shape


I am trying to implement the generalized Hough transform in matlab. The algorithm requires the gradient direction at each point in the shape. How can I measure phi as shown in the figure below?

enter image description here


Solution

  • The normal to the curve [x(t), y(t)] is [-dy(t)/dt, dx(t)/dt]. Thus, with x being the x-coordinates and y the y-coordinates, the normals are

    [-diff(y(:)),diff(x(:))]
    

    and the angle phi is

    atan2(diff(x(:)),-diff(y(:)))