--- In
[hidden email], "ekremguner7" <ekremguner7@...> wrote:
>
> hi i want to calculate the angles of gradients in a image.
> i look at magnitude.txt in Files\Howto's section.
> I use this code (function) but, i can not give a meaning to values
> returnd as the angles.
> Simple manner i just want to find the gradient angle of white line in a
> dark background.
> Please help & enlight me. I stuck at here.
>
>
> [Non-text portions of this message have been removed]
>
First get the sobel derivatives (in the X direction and the Y
direction) of the image using cvSobel:
(make sure they are 16 or 32 bit)
CvMat* dx = cvCreatemat(....CV_32F)
CvMat* dy = cvCreateMat(....CV_32F)
cvSobel(src,dx,0,1,3);
cvSobel(src,dy,1,0,3);
When you have those values, the orientation can be gotten by:
orientation(i,j) = atan( dx(i,j) , dx(i,j) ) * 180/PI
so the orientation of any edge point is the inverse tan of the X
gradient gradient at that point divided by the Y gradient strength at
that point
To get the proper magnitude is easy as well:
magnitude(i,j) = sqrt( pow(dx(i,j),2) + pow(dy(i,j),2)
So the vector magnitude of the edge point at i,j is the square root of
dx(i,j) squared plus dy(i,j) squared