Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Computing gradient direction of image


I am trying to calculate the gradient direction of an image.

I tried the following function:

Mat computeArcTan(Mat &dst1, Mat &dst2)
   Mat angle;//(dst1.rows,dst1.cols,CV_32F);
   ofstream myFile("angle.csv");
   const double pi = 3.14159;

   for(int row = 0; row < dst1.rows; row++)
       for(int col = 0; col < dst1.cols; col++ )
           myFile <<<double>(row,col) <<",";

            myFile << endl;
   return angle;

the dst1 and dst2 are the gradient of x and y direction. However, I believe I am not getting the correct direction values. The values printed in the csv file is a repetition of values of 0, 18.435, 45 and 71.3872. When i checked with matlab, it is totally wrong. I know openCV has the function cartToPolar() but I'm trying to hard code it just to understand the process behind it.

Any Ideas or direction/suggestion on what am i doing wrong ?