I have been business a histogram equalisation method. I've used [this question](https://stackoverflow.com/questions/32015287/histogram-equalization-using-java) as a foundation to build on. However I cannot get this code to run and Google isn't too helpful in helping me find the issue. I pass in a JPG BufferedImage object. I first display the image so I see what I'm working with and then process it. However it ALWAYS fails on the line int `valueBefore=img.getRaster().getPixel(x, y,iarray)[0];` and I'm not sure why. The error I get is `Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1` but I cannot see *why* it gives this error, the picture is there and filled with pixels!

```
public BufferedImage hisrogramNormatlisation(BufferedImage img) {
        // To view image we're working on
        JFrame frame = new JFrame();
        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(new JLabel(new ImageIcon(img)));
        frame.pack();
        frame.setVisible(true);

        int width =img.getWidth();
        int height =img.getHeight();
        int anzpixel= width*height;
        int[] histogram = new int[255];
        int[] iarray = new int[1];
        int i =0;

        // Create histogram
        for (int x = 50; x < width; x++) {
            for (int y = 50; y < height; y++) {
                int valueBefore=img.getRaster().getPixel(x, y,iarray)[0];
                histogram[valueBefore]++;
                System.out.println("here");
            }
        }

         int sum = 0;

         float[] lut = new float[anzpixel];
         for ( i=0; i < 255; ++i )
         {
             sum += histogram[i];
             lut[i] = sum * 255 / anzpixel;
         }

         i=0;
         for (int x = 1; x < width; x++) {
             for (int y = 1; y < height; y++) {
                 int valueBefore=img.getRaster().getPixel(x, y,iarray)[0];
                 int valueAfter= (int) lut[valueBefore];
                 iarray[0]=valueAfter;
                  img.getRaster().setPixel(x, y, iarray); 
                  i=i+1;
             }
         }
         return img;
    }

```

Error description:

```
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at java.awt.image.ComponentSampleModel.getPixel(ComponentSampleModel.java:n)
    at java.awt.image.Raster.getPixel(Raster.java:n)
    at MainApp.hisrogramNormatlisation(MainApp.java: * line described *)
    at MainApp.picture(MainApp.java:n)
    at MainApp.<init>(Main.java:n)
    at MainApp.main(Main.java:n)

```