title: Convert Image to Grayscale with array matrix RGB java
body: <p>I'm creating an Image filter program and I want to convert a coloured picture to a grayscale picture with the help of an array matrix.</p>
  
  <p>This is what I have currently:</p>
  
  <pre><code>import java.awt.Color;
  import se.lth.cs.ptdc.images.ImageFilter;
  
  public class GrayScaleFilter extends ImageFilter {
  
      public GrayScaleFilter(String name){
          super(name);
      }
  
      public Color[][] apply(Color[][] inPixels, double paramValue){
          int height = inPixels.length;
          int width = inPixels[0].length;
          Color[][] outPixels = new Color[height][width];
          for (int i = 0; i &lt; 256; i++) {
            grayLevels[i] = new Color(i, i, i);
          }
  
          for(int i = 0; i &lt; height; i++){
              for(int j = 0; j &lt; width; j++){
                  Color pixel = inPixels[i][j];
              outPixels[i][j] = grayLevels[index];                    
              }
          }
          return outPixels;
      }
  }
  </code></pre>
  
  <p>It looks like I'm supposed to use this formula: ((R+G+B)/3)</p>
  
  <p>I want to create an array matrix like this: </p>
  
  <pre><code> Color[] grayLevels = new Color[256];
      // creates the color (0,0,0) and puts it in grayLevels[0],
      // (1,1,1) in grayLevels[1], ..., (255,255,255) in grayLevels[255]
  </code></pre>
  
  <p>This is the class I'm refering too when I want to use grascale:</p>
  
  <pre><code>public abstract Color[][] apply(Color[][] inPixels, double paramValue);
  
  protected short[][] computeIntensity(Color[][] pixels) {
      int height = pixels.length;
      int width = pixels[0].length;
      short[][] intensity = new short[height][width];
      for (int i = 0; i &lt; height; i++) {
          for (int j = 0; j &lt; width; j++) {
              Color c = pixels[i][j];
              intensity[i][j] = (short) ((c.getRed() + c.getGreen() + c
                      .getBlue()) / 3);
          }
      }
      return intensity;
  }
  </code></pre>
  
  <p>Any feedback on how I can achieve this? Instead of using <code>outPixels[i][j] = new Color(intensity, intensity, intensity);</code></p>