I used imgradientxy() ;but it gives values like -600.i need values of angle in range -180 to 180. in both direction separately.
The values are 0 and 90. The gradient is calculated in the X and Y direction by imgradientxy()
as you may infer from its name.
However the gradient in a point is defined by:
and you can do [Gx,Gy]=imgradientxy(img)
.
That means that your total gradient (not the "directional gradient", which is what Gx and Gy are) is a vector. the (Gxi,Gyi)
vector in point i
.
To calculate the modulus and angle of a vector is a straightforward algebra thing:
The modulus, magnitude, euclidean norm or however you preffer to call it is:
m=norm([Gx,Gy]);
And the angle:
theta=atan2(Gy,Gx); %radians
theta=atand(Gy/Gx); %degrees