title: calculate gradient directions
body: <p>I want calculate angles of gradients from depth map and group it for some directions (8 sectors)
  But my function calculates only first 3 directions </p>
  
  <pre><code>cv::Mat calcAngles(cv::Mat dimg)//dimg is depth map
  {   
      const int directions_num = 8;//number of directions
      const int degree_grade = 360;
      int range_coeff = 255 / (directions_num + 1);//just for visualize
      cv::Mat x_edge, y_edge, full_edge, angles;
      dimg.copyTo(x_edge);
      dimg.copyTo(y_edge);
      dimg.copyTo(full_edge);
          //compute gradients
  
      Sobel( dimg, x_edge,    CV_8U, 1, 0, 5, 1, 19, 4 );
      Sobel( dimg, y_edge,    CV_8U, 0, 1, 5, 1, 19, 4 );
      Sobel( dimg, full_edge, CV_8U, 1, 1, 5, 1, 19, 4 );
  
      float freq[directions_num + 1];//for collect direction's frequency
      memset(freq, 0, sizeof(freq));
  
      angles = cv::Mat::zeros(dimg.rows, dimg.cols, CV_8U);//store directions here
      for(int i = 0; i &lt; angles.rows; i++)
      {
          for(int j = 0; j &lt; angles.cols; j++)
          {
              angles.at&lt;uchar&gt;(i, j) = (((int)cv::fastAtan2(y_edge.at&lt;uchar&gt;(i, j), x_edge.at&lt;uchar&gt;(i, j))) / (degree_grade/directions_num) + 1
                  ) * (dimg.at&lt;uchar&gt;(i, j) ? 1 : 0);//fastatan returns values from 0 to 360, if i not mistaken. I want group angles by directions_num sectors. I use first 'direction' (zero value) for zero values from depth map (zero value at my depth map suggest that it is bad pixel)  
              freq[angles.at&lt;uchar&gt;(i, j)] += 1;
          }
      }
      for(int i = 0; i &lt; directions_num + 1; i++) 
      {
          printf("%2.2f\t", freq[i]);
      }
      printf("\n");
      angles *= range_coeff;//for visualization
      return angles;
  }
  </code></pre>
  
  <p>Out from one of the frames:</p>
  
  <pre><code>47359.00        15018.00        8199.00 6224.00 0.00    0.00    0.00    0.00    0.00
  </code></pre>
  
  <p>(first value is "zero pixel", next is number of gradients in n-place but only 3 are not zero)</p>
  
  <p>Visualization</p>
  
  <p><img src="https://i.stack.imgur.com/BHoys.png" alt="enter image description here"></p>
  
  <p>Is there way out? Or these result is OK?
  PS Sorry for my writing mistakes. English in not my native language.</p>