Java BufferedImage Histogram imageHistogram(BufferedImage input)

Here you can find the source of imageHistogram(BufferedImage input)

Description

image Histogram

License

Apache License

Declaration

public static int[] imageHistogram(BufferedImage input) 

Method Source Code

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

Related

  1. generateBWHistogram(BufferedImage bitmap, int bucketSize)
  2. histogram(BufferedImage bufferedImage)
  3. histogram(BufferedImage img, boolean gray)
  4. imageHistogram(BufferedImage input)
  5. sectorHistorgramCompare(BufferedImage a, BufferedImage b)