title: Image Convolution not working according to the actual algorithm
body: <p>I have implemented a convolution filter in java. I did this a while back in ap cs but now I actually need it for something, so I re implemented it to make sure I still know how to do it. Unfortunately I lost my working copy so I can't compare current code to my previous working code. I am pretty sure I am implementing the algorithm correctly, but the code is still not working properly. Can an experienced programmer please explain what I am doing wrong.</p>
  
  <p>Here is the Convolution class:</p>
  
  <pre><code>import java.awt.*;
  import java.util.Arrays;
  
  public class ConvolutionFilter {
  
      private int[][] image;
      private int[][] weights;
      private double[][] doubleWeights;
  
      private int[][] convolved;
  
      public ConvolutionFilter(int[][] image, int[][] weights) {
  
          this.image = image;
          this.weights = weights;
  
          convolve();
      }
  
      public void convolve() {
  
          int sum;
          int[][] convolved = new int[image.length][image[0].length];
  
          for (int r = 0; r &lt; convolved.length - weights.length - 1; r++) {
              for (int c = 0; c &lt; convolved[r].length - weights.length - 1; c++) {
                  sum = 0;
                  for (int i = 0; i &lt; weights.length; i++) {
                      for (int j = 0; j &lt; weights[i].length; j++) {
                          sum += image[r + i][c + j] * weights[i][j];
                      }
                  }
                  convolved[r][c] = sum / weight();
              }
          }
  
          this.convolved = convolved;
      }
  
      public int numWeights() {
          return weights.length * weights[0].length;
      }
  
      public int weight() {
          int sum = 0;
          for (int r = 0; r &lt; weights.length; r++) {
              for (int c = 0; c &lt; weights[r].length; c++) {
                  sum += weights[r][c];
              }
          }
          if (sum == 0) return 1; else return sum;
      }
  
      public int[][] getConvolved() {
          return convolved;
      }
  
  }
  </code></pre>
  
  <p>Any help is appreciated!</p>