title: Sobel edge implementation issue
body: <p>For a class I have to implement the sobel edge detector in java, and do I did. But something isnt right, and after 3 hours trying to figure it out I still havent.</p>
  <pre><code>public static Color[][] sobelBorder (Color[][] img) {
          Color[][] original = ImageUtils.cloneArray(img);
          Color[][] tmp = grayscale(original);
  
  
          int[][] kernel1 = {
                  {1,0,-1},
                  {2,0,-2},
                  {1,0,-1}
          };
  
          int[][] kernel2 = {
                  {1,2,1},
                  {0,0,0},
                  {-1,-2,-1}
          };
  
          for( int i = 1; i &lt; tmp.length -1; i++) {
              for( int j = 1; j &lt; tmp[0].length -1; j++) {
  
                  int r1 = 0;
                  int r2 = 0;
  
                  int g1 = 0;
                  int g2 = 0;
  
                  int b1 = 0;
                  int b2 = 0;
  
                  for( int x = 0; x &lt; 3; x++) {
                      for( int y = 0; y &lt; 3; y++) {
  
                          int aR = (tmp[i + (x - 1)][j + (y - 1)].getRed());
                          int aG = (tmp[i + (x - 1)][j + (y - 1)].getGreen());
                          int aB = (tmp[i + (x - 1)][j + (y - 1)].getBlue());
  
                          r1 = r1 + (aR * kernel1[x][y]);
                          r2 = r2 + (aR * kernel2[x][y]);
  
                          g1 = g1 + (aG * kernel1[x][y]);
                          g2 = g2 + (aG * kernel2[x][y]);
  
                          b1 = b1 + (aB * kernel1[x][y]);
                          b2 = b2 + (aB * kernel2[x][y]);
  
                      }
                  }
  
                  int finalR = (int) Math.sqrt((r1 * r1) + (r2 * r2));
                  int finalG = (int) Math.sqrt((g1 * g1) + (g2 * g2));
                  int finalB = (int) Math.sqrt((b1 * b1) + (b2 * b2));
  
                  finalR = threshold(finalR, 100);
                  finalG = threshold(finalG, 100);
                  finalB = threshold(finalB, 100);
  
                  tmp[i][j] = new Color(finalR, finalG, finalB);
              }
          }
  
          return tmp;
      }
  </code></pre>
  <p>The final RBG values are coming way to high, and the result always come mostly white.</p>
  <p>What I am doing wrong?</p>
  <p>*<strong>Edit:</strong>
  <strong>Here are the threshold and greyscale funcs:</strong></p>
  <pre><code>public static Color[][]grayscale(Color[][] img) {
          Color[][] tmp = ImageUtils.cloneArray(img);
  
          for( int i = 0; i &lt; tmp.length; i++)
          {
              for( int j = 0; j&lt; tmp[i].length;j++) {
  
                  Color pixel = tmp[i][j];
                  int r = pixel.getRed();
                  int g = pixel.getGreen();
                  int b = pixel.getBlue();
  
                  int grayNum = (r + g + b)/3;
                  tmp[i][j] = new Color (grayNum, grayNum, grayNum);
              }
          }
          return tmp;
      }
  
      public static int threshold (int pixel, int threshold) {
          if(pixel &gt; threshold){
              return 255;
          }else return 0;
  
      }
  </code></pre>