Here you can find the source of imageHistogram(BufferedImage input)
public static int[] imageHistogram(BufferedImage input)
//package com.java2s; //License from project: Apache License import java.awt.image.BufferedImage; public class Main { public static int[] imageHistogram(BufferedImage input) { int[] rhistogram = new int[256]; int[] ghistogram = new int[256]; int[] bhistogram = new int[256]; for (int i = 0; i < rhistogram.length; i++) rhistogram[i] = ghistogram[i] = bhistogram[i] = 0; for (int j = 0; j < input.getHeight(); j++) { for (int i = 0; i < input.getWidth(); i++) { int rgb = input.getRGB(i, j); int r = (rgb >> 16) & 0xFF; int g = (rgb >> 8) & 0xFF; int b = (rgb) & 0xFF; // Increase the values of colors rhistogram[r]++;/*from w w w . j ava 2 s . c om*/ ghistogram[g]++; bhistogram[b]++; } } return joinArray(rhistogram, ghistogram, bhistogram); } private static int[] joinArray(int[]... arrays) { int length = 0; for (int[] array : arrays) { length += array.length; } final int[] result = new int[length]; int offset = 0; for (int[] array : arrays) { System.arraycopy(array, 0, result, offset, array.length); offset += array.length; } return result; } }