title: How to improve invert + grayscale operator in Java?
body: <p>I want to invert and gray scale an image. Here is my original image:<br>
  <img src="https://i.stack.imgur.com/B8ZS9.png" alt="enter image description here"></p>
  
  <p>Here is the final result I want to achieve (produced with Paint.NET):<br>
  <img src="https://i.stack.imgur.com/sO4EK.png" alt="enter image description here"></p>
  
  <p>However using some (basic?) Java code found on Internet, I only get the picture below:
  <img src="https://i.stack.imgur.com/tCRIY.png" alt="enter image description here"></p>
  
  <p>Here is the code I used:</p>
  
  <pre><code>private static final byte[] invertTable;
  
  static {
      invertTable = new byte[256];
      for (int i = 0; i &lt; 256; i++) {
          invertTable[i] = (byte) (255 - i);
      }
  }
  
  private static BufferedImage grayScale(BufferedImage source) {
      ColorConvertOp grayScale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
  
      return grayScale.filter(source,null);
  }
  
  private static BufferedImage invertImage(final BufferedImage src) {
      final int w = src.getWidth();
  
      final int h = src.getHeight();
  
      final BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
  
      final BufferedImageOp invertOp = new LookupOp(new ByteLookupTable(0, invertTable), null);
  
      return invertOp.filter(src, dst);
  }
  
  // ...
  BufferedImage sourceImage = ...
  BufferedImage convertedImage = grayScale(invertImage(sourceImage));
  </code></pre>
  
  <p>How can I improve the above code?</p>