Java BufferedImage Operation buildColorStatisticsOfImage(BufferedImage image)

Here you can find the source of buildColorStatisticsOfImage(BufferedImage image)

Description

Builds a statistical map with all found colors as keys within a given image.

License

Open Source License

Parameter

Parameter Description
image The image to operate on

Return

A Map with

Declaration

private static Map<Integer, Integer> buildColorStatisticsOfImage(BufferedImage image) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**//ww w.  jav a  2 s  .  c o  m
     * Builds a statistical map with all found colors as keys within a given
     * image. The values of the map represent the amount pixels found in the
     * key-colour.
     * 
     * @param image
     *            The image to operate on
     * @return A Map with <colorcode, amount>
     */
    private static Map<Integer, Integer> buildColorStatisticsOfImage(BufferedImage image) {

        Map<Integer, Integer> colorStatistics = new HashMap<Integer, Integer>();

        for (int i = 0; i < image.getWidth(); i++) {
            for (int j = 0; j < image.getHeight(); j++) {

                int rgb = image.getRGB(i, j);

                Integer counter = (Integer) colorStatistics.get(rgb);

                if (counter == null) {
                    counter = 0;
                }

                counter++;
                colorStatistics.put(new Integer(rgb), counter);
            }
        }
        return colorStatistics;
    }
}

Related

  1. binarize(BufferedImage image)
  2. binarize(BufferedImage original)
  3. binary(BufferedImage src)
  4. blackAndWhiteCleaning(BufferedImage image)
  5. boostBufferedImagePerformance(BufferedImage image, boolean translucent)
  6. buildingCoordinatesInImage(BufferedImage imageSection)
  7. buildPixelAverages(BufferedImage a, Rectangle[] sectors)
  8. buildSectors(BufferedImage a, int sqrtSectors)
  9. cascadeHorizontal(final BufferedImage... images)