title: Calculate gradient directions using java
body: <p>I'm trying to code a function that calculate an orientation or gradient directions of image without using the Built-in method in boofCV library which is </p>
  
  <pre><code> GradientToEdgeFeatures.direction(derivX,derivY,orientation);
  </code></pre>
  
  <p>derivX is image derivative in x-direction.
  derivY is image derivative in Y-direction.
  orientation is image for storing the value of gradient directions.
  magnitude is image for storing the value of gradient directions.
  The output from the last Built-in method for 3x3 image= <br/></p>
  
  <p>Orientation 1.5707964<br/>
  Orientation 1.5707964<br/>
  Orientation 1.5707964<br/>
  Orientation 1.5707964<br/>
  Orientation 1.5707964<br/>
  Orientation 1.5707964<br/>
  Orientation 1.5707964<br/>
  Orientation 1.5707964<br/>
  Orientation 1.5707964<br/></p>
  
  <p>I wrote the code for this step and also for calculating the Magnitude as following:</p>
  
  <pre><code>         for (int i = 0; i &lt; Orientation.getHeight(); i++) {
                  for (int j = 0; j &lt; orientation.getWidth(); j++) {
                      float valueOfOrientation =  (float) ((float)Math.atan2(derivY.get(j, i), derivX.get(j, i)));
                      orientation.set(j, i,valueOfOrientation);
                      System.out.println("Orientation"+valueOfOrientation );
  
  
                     }
                  }
  
           for (int i = 0; i &lt; (magnitude.getHeight()); i++) {
                  for (int j = 0; j &lt;( magnitude.getWidth()); j++) {
  
                      float valueXMag=(float) Math.pow(derivX.get(j, i),2);
                      float valueYMag=(float) Math.pow(derivY.get(j, i),2);
                      float magnitudeValue=(float) Math.sqrt(valueXMag+valueYMag);
                      magnitude.set(j, i,magnitudeValue );
                      System.out.println("Magnitude  "+magnitudeValue);
  
                      }
                  }
  </code></pre>
  
  <p>But the value of output for 3x3 Image=<br/></p>
  
  <p>Orientation-1.5707964<br/>
  Orientation-1.5707964<br/>
  Orientation-1.5707964<br/>
  Orientation-1.5707964<br/>
  Orientation0.0<br/>
  Orientation-1.5707964<br/>
  Orientation-1.5707964<br/>
  Orientation-1.5707964<br/>
  Orientation-1.5707964<br/></p>
  
  <p>Magnitude  1.9073486E-6<br/>
  Magnitude  1.9073486E-6<br/>
  Magnitude  1.9073486E-6<br/>
  Magnitude  1.9073486E-6<br/>
  Magnitude  0.0<br/>
  Magnitude  1.9073486E-6<br/>
  Magnitude  1.9073486E-6<br/>
  Magnitude  1.9073486E-6<br/>
  Magnitude  1.9073486E-6<br/></p>
  
  <p>which is not equal to the Built-in method.<br/>
  What is causing this and how can I solve this? Thanks in advance!<br/></p>
  
  <p>P.S Sorry for my writing mistakes. English in not my native language.</p>