java.lang.Object
imagingbook.common.color.statistics.ColorHistogram
This class calculates a color histogram of a set of colors (i.e., a color image). Only the unique colors are
accounted for. Colors are supplied as ARGB-encoded integers (A = alpha values being ignored). Colors are internally
sorted by their frequency (in descending order). Used mainly for color quantization.
- Version:
- 2022/11/05
-
Constructor Summary
ConstructorsConstructorDescriptionColorHistogram
(int[] pixels) Creates a color histogram instance from the supplied sequence of color pixel values (assumed to be aRGB-encoded integers).ColorHistogram
(int[] pixelsOrig, boolean sortByFrequency) Creates a color histogram instance from the supplied sequence of color pixel values (assumed to be ARGB-encoded integers). -
Method Summary
Modifier and TypeMethodDescriptionint
getColor
(int index) Returns the unique color with the given index.int[]
Returns an array with all (distinct) colors of this histogram as sRGB int-encoded values.int[]
Returns an array with the frequencies of all (distinct) colors of this histogram.int
getFrequency
(int index) Returns the frequency of the unique color with the given index.int
Returns the number of distinct colors in this color histogram.void
Lists the unique colors to System.out (intended for debugging only).
-
Constructor Details
-
ColorHistogram
Creates a color histogram instance from the supplied sequence of color pixel values (assumed to be aRGB-encoded integers). The original pixel values are not modified.- Parameters:
pixels
- aRGB-encoded integer pixel data
-
ColorHistogram
Creates a color histogram instance from the supplied sequence of color pixel values (assumed to be ARGB-encoded integers). The original pixel values are not modified.- Parameters:
pixelsOrig
- original pixel values (not modified)sortByFrequency
- set true to sort the final colors by descending frequency
-
-
Method Details
-
getNumberOfColors
Returns the number of distinct colors in this color histogram.- Returns:
- the number of distinct colors.
-
getColors
Returns an array with all (distinct) colors of this histogram as sRGB int-encoded values. Values are in no particular order but in the same order as the array returned bygetFrequencies()
.- Returns:
- an array of all distinct colors
-
getFrequencies
Returns an array with the frequencies of all (distinct) colors of this histogram. Values are in no particular order but in the same order as the array returned bygetColors()
.- Returns:
- an array of all distinct color frequencies
-
getColor
Returns the unique color with the given index. Colors are sorted by (decreasing) frequency.- Parameters:
index
- The color index.- Returns:
- The color, encoded as an ARGB integer (A is zero).
-
getFrequency
Returns the frequency of the unique color with the given index. Colors are sorted by (decreasing) frequency.- Parameters:
index
- The color index.- Returns:
- The frequency of the color.
-
listUniqueColors
Lists the unique colors to System.out (intended for debugging only).
-