Reputation: 33
I am having doubt to the used equation in the function of imgradient
.
In the line of 127:
Gdir = atan2(-Gy,Gx)*180/pi; % Radians to degrees
Why the Gy
have to be negative?
Upvotes: 3
Views: 309
Reputation: 165
Image coordinate has different basis compared to standard basis used by imgradient.
Introducing one more minus on Gy term for atan2() brings us with the same affect.
Upvotes: 0
Reputation: 60635
The y-axis is inverted in images (it increases downward instead of upward). This causes the angles to increase clockwise instead of counter-clockwise as you're used to. By flipping the y component of the gradient, this line computes an angle in the "normal" sense.
Using the graph that @Dan linked in his comment:
In this graph, y increases upward, and angles increase counter-clockwise. In an image, the coordinate system is flipped. This leads to counter-intuitive angles. Hence they invert the y axis to compute the angle.
Upvotes: 2