Here you can find the source of buildPixelAverages(BufferedImage a, Rectangle[] sectors)
private static int[][] buildPixelAverages(BufferedImage a, Rectangle[] sectors)
//package com.java2s; //License from project: Apache License import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.awt.image.WritableRaster; public class Main { private static int[][] buildPixelAverages(BufferedImage a, Rectangle[] sectors) { WritableRaster raster = a.getRaster(); int[][] result = new int[sectors.length][]; for (int s = 0; s < sectors.length; s++) { Rectangle sector = sectors[s]; int[] total = new int[4]; int[] pixel = new int[4]; for (int x = sector.x; x < sector.x + sector.width; x++) { for (int y = sector.y; y < sector.y + sector.height; y++) { pixel = raster.getPixel(x, y, pixel); total[0] += pixel[0]; total[1] += pixel[1]; total[2] += pixel[2]; }//from ww w . j a v a 2 s.c o m } int pixels = sector.width * sector.height; int[] average = new int[] { total[0] / pixels, total[1] / pixels, total[2] / pixels }; result[s] = average; } return result; } }