I need help in the following. I have 7500 picturewidth and want to read 5 lines from that picture, so pictureheight = 5. It is a raw image format file.

I am reading the correct pixels so far. But my purpose is to count the number of pixels to show the average on my graph. So I do not want to show the given pixel number but the average from all lines which I am counting.
With average I mean, when I read one line, there are values which are used to show in the graph. I need to count these values and divide them into the number of all values.

Here is what I have so far. Thanks so far for your hints...


Java Code:
private XYSeriesCollection createDataset() {

    try {
        final int pictureWidth = 7500;
        final int pictureHeight = 5;
        int pictureArray[] = new int[pictureWidth * pictureHeight];
        int pixArray[] = new int[pictureWidth];
        int R, G, B, U;
        int averageX, averageY;

        FileInputStream inp = new FileInputStream("d:\\DO_18-02-2014_19-59-05-756_00010.img");

        int k = 0;

        XYSeries RED = new XYSeries("R");   
        XYSeries GREEN = new XYSeries("G");  
        XYSeries BLUE = new XYSeries("B");
        XYSeries  UNDEFINED = new XYSeries("U");

        for (int j = 0; j < pictureHeight; j++) {
            for (int i = 0; i < pictureWidth; i++) {
                R = inp.read();
                G = inp.read();
                B = inp.read();
                U = inp.read();
                Color c = new Color(R, G, B, U);
                pictureArray[k++] = c.getRGB();

                System.out.println((new Integer(i)).toString()+" "+(new Integer(j)).toString());

                RED.add(i, R);
                GREEN.add(i, B);
                BLUE.add(i, G);
                UNDEFINED.add(i, U);
            }
        }
        inp.close();

        final XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(RED);
        dataset.addSeries(GREEN);
        dataset.addSeries(BLUE);
        dataset.addSeries(UNDEFINED);

        return dataset;
    }
    catch (Exception e) {
        JOptionPane.showMessageDialog(null, e, "Exception Raised", JOptionPane.INFORMATION_MESSAGE);
        return null;
    }
}