title: How to change the contrast and brightness of an image stored as pixel values
body: <p>I have an image that is stored as an array of pixel values. I want to be able to apply a brightness or contrast filter to this image. Is there any simple way, or algorithm, that I can use to achieve this.</p>
  
  <p>Here is my code...</p>
  
  <pre><code>   PlanarImage img=JAI.create("fileload","C:\\aimages\\blue_water.jpg");
     BufferedImage image = img.getAsBufferedImage();
  
     int w = image.getWidth();
     int h = image.getHeight();
     int k = 0;
  
     int[] sbins = new int[256];
     int[] pixel = new int[3];
  
     Double d = 0.0;
     Double d1;
     for (int x = 0; x &lt; bi.getWidth(); x++) {
         for (int y = 0; y &lt; bi.getHeight(); y++) {
             pixel = bi.getRaster().getPixel(x, y, new int[3]);
             k = (int) ((0.2125 * pixel[0]) + (0.7154 * pixel[1]) + (0.072 * pixel[2]));
             sbins[k]++;
         }
     }
  </code></pre>