ggplayerlek
ggplayerlek

Reputation: 33

About imgradient function in Matlab

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

Answers (2)

Mou
Mou

Reputation: 165

Image coordinate has different basis compared to standard basis used by imgradient.

Linear transform for image coordinate

Introducing one more minus on Gy term for atan2() brings us with the same affect.

Upvotes: 0

Cris Luengo
Cris Luengo

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:

circle with angles on it

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

Related Questions