Java BufferedImage Histogram imageHistogram(BufferedImage input)

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

Description

image Histogram

License

Open Source License

Parameter

Parameter Description
input a parameter

Return

Return histogram of grayscale image

Declaration

public static int[] imageHistogram(BufferedImage input) 

Method Source Code


//package com.java2s;
/*//from   www. j a v  a 2s  . com
  This file is part of Cuber.
    
Cuber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
Cuber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Cuber.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Color;

import java.awt.image.BufferedImage;

public class Main {
    /**
     * @param input
     * @return Return histogram of grayscale image
     * @since 21/06/2013
     * @author wonka
     */
    public static int[] imageHistogram(BufferedImage input) {
        int[] histogram = new int[256];

        for (int i = 0; i < histogram.length; i++) {
            histogram[i] = 0;
        }

        for (int i = 0; i < input.getWidth(); i++) {
            for (int j = 0; j < input.getHeight(); j++) {
                int red = new Color(input.getRGB(i, j)).getRed();
                histogram[red]++;
            }
        }

        return histogram;
    }
}

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)