Java BufferedImage Operation buildPixelAverages(BufferedImage a, Rectangle[] sectors)

Here you can find the source of buildPixelAverages(BufferedImage a, Rectangle[] sectors)

Description

build Pixel Averages

License

Apache License

Declaration

private static int[][] buildPixelAverages(BufferedImage a, Rectangle[] sectors) 

Method Source Code

//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;
    }
}

Related

  1. binary(BufferedImage src)
  2. blackAndWhiteCleaning(BufferedImage image)
  3. boostBufferedImagePerformance(BufferedImage image, boolean translucent)
  4. buildColorStatisticsOfImage(BufferedImage image)
  5. buildingCoordinatesInImage(BufferedImage imageSection)
  6. buildSectors(BufferedImage a, int sqrtSectors)
  7. cascadeHorizontal(final BufferedImage... images)
  8. changeContrast(BufferedImage img, float amount)
  9. changeImageToArray(BufferedImage bufferedImage)