title: Code for image convolution not displaying an image properly?
body: <p>So heres the deal: I tried simplifiying (to the user) how to execute convolution. I tried using this to run a Sobel filter and when i try to display the image (via jfram and image icon) the image icon doesnt pop up, it just a big gray square.  </p>
  
  <p>The jframe/imageicon worked flawlessly until i tried to get it to display the output of the result of this filter. </p>
  
  <pre><code>    float[][] sobel = { { -1, 0, 1},
                     { -2, 0, 2},
                     {-1, 0, 1} };
  someObject test = new someObject(filepath);
  test.convolutionFilter(sobel);
  
  public BufferedImage convolutionFilter(float[][] filter) {
      int columns = filter.length;
      int  rows= filter[0].length;
      float numTemp;
      float[] filter1D = new float[columns*rows];
      for (int j = 0; j&lt;rows; j++) {
          for (int i= 0; i&lt; columns; i++ ) {
              numTemp = filter[j][i];
              System.out.print(numTemp + " ");
              filter1D[j*columns + i] = numTemp;
          }
      }
  
  
      Kernel kern = new Kernel(rows, columns, filter1D);
      ConvolveOp op = new ConvolveOp(kern);
  
      BufferedImage temp = new BufferedImage(processedImage.getWidth(), processedImage.getHeight(), BufferedImage.TYPE_INT_ARGB); 
      op.filter(processedImage, temp);
      processedImage = temp;
      return processedImage;
  
  }
  </code></pre>
  
  <p><strong>CODE HAS BEEN UPDATED</strong></p>
  
  <p>If i do the following my gui will display a plane gray frame with no image. If I do one command and not the other, the image will display perfectly. 
  BufferedImage testImage = ImageIO.read(filepath); </p>
  
  <pre><code>float[][] sobelFilter = { { -1, 0, 1}, 
                    { -2, 0, 2}, 
                    { -1, 0, 1} }; 
  testImage = SimpleImage.toGrayscale(testImage); 
  testImage =  SimpleImage.convolutionFilter(testImage, sobelFilter); 
  //use some swing functions to display image 
  </code></pre>
  
  <p>if I JUST convert to grayscale I will get correct results, if i just apply JUST the filter I will get correct results. If I Complete this AS IS I get a Blank GUI screen that popsup. If I swap the order that they are executed (filter first then convert to grayscale) I will get results. </p>
  
  <p>I think something with the grayscale conversion process is screwing up the convolution</p>
  
  <p>toGrayscale should convert the image to grayscale </p>
  
  <p>convolutionFilter should take a 2D image filter, unroll it into 1D array and then convolve the processedImage and return the result. </p>
  
  <pre><code>public class SimpleImage { 
  public static BufferedImage toGrayscale(BufferedImage processedImage) { 
       BufferedImage tempImage = new BufferedImage(processedImage.getWidth(), processedImage.getHeight(), processedImage.getType()); 
       BufferedImageOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);  
       tempImage = op.filter(processedImage, null);  
       return tempImage; 
  }   
  
  
  public static BufferedImage convolutionFilter(BufferedImage processedImage, float[][] filter2D) {     
      BufferedImage tempImage = new BufferedImage(processedImage.getWidth(), processedImage.getHeight(), processedImage.getType()); 
      int columns = filter2D.length; 
      int  rows= filter2D[0].length; 
      //Unrolls a 2D filter into a 1D filter 
      float[] filter1D = new float[columns*rows]; 
      for (int j = 0; j&lt;rows; j++) { 
              for (int i= 0; i&lt; columns; i++ ) { 
              filter1D[j*columns + i] = filter2D[j][i]; 
          } 
      } 
      //creates Kernal and convolution operator 
      Kernel kern = new Kernel(rows, columns, filter1D); 
      ConvolveOp op = new ConvolveOp(kern); 
      //apply filtering  
      tempImage = op.filter(processedImage, null); 
      return tempImage; 
  
      } 
   } 
  </code></pre>