Java BufferedImage Histogram generateBWHistogram(BufferedImage bitmap, int bucketSize)

Here you can find the source of generateBWHistogram(BufferedImage bitmap, int bucketSize)

Description

generate BW Histogram

License

Open Source License

Declaration

public static int[] generateBWHistogram(BufferedImage bitmap, int bucketSize) 

Method Source Code


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

Related

  1. histogram(BufferedImage bufferedImage)
  2. histogram(BufferedImage img, boolean gray)
  3. imageHistogram(BufferedImage input)
  4. imageHistogram(BufferedImage input)