Here you can find the source of generateBWHistogram(BufferedImage bitmap, int bucketSize)
public static int[] generateBWHistogram(BufferedImage bitmap, int bucketSize)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.image.BufferedImage; public class Main { public static int[] generateBWHistogram(BufferedImage bitmap, int bucketSize) { int[] histogram = new int[256 / bucketSize]; for (int y = 0; y < bitmap.getHeight(); y++) { for (int x = 0; x < bitmap.getWidth(); x++) { Color c = new Color(bitmap.getRGB(x, y)); int grey = (c.getRed() + c.getBlue() + c.getGreen()) / 3; int index = grey / bucketSize; histogram[index]++;//from w ww .j a v a2 s.com } } return histogram; } }