- All Implemented Interfaces:
ColorQuantizer
This is an implementation of Heckbert's median-cut color quantization algorithm [1]. Unlike in the original algorithm, no initial uniform (scalar) quantization is used to for reducing the number of image colors. Instead, all colors contained in the original image are considered in the quantization process. After the set of representative colors has been found, each image color is mapped to the closest representative in RGB color space using the Euclidean distance. See Sec. 13.4.2 (Algs. 13.1-3) of [2] for details.
The quantization process has two steps: first a ColorQuantizer
instance is created from a given image using
one of the constructor methods provided. This quantizer can then be used to quantize the original image or any other
image using the same set of representative colors (color table).
[1] Heckbert P., "Color Image Quantization for Frame Buffer Display", ACM Transactions on Computer Graphics
(SIGGRAPH), pp. 297-307 (1982).
[2] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic
Introduction, 3rd ed, Springer (2022).
- Version:
- 2022/10/05 revised to use PriorityQueue, made deterministic
-
Field Summary
Fields inherited from interface imagingbook.common.color.quantize.ColorQuantizer
MAX_RGB
-
Constructor Summary
ConstructorsConstructorDescriptionMedianCutQuantizer
(int[] pixels, int K) Constructor, creates a newMedianCutQuantizer
with up to K colors, but never more than the number of colors found in the supplied pixel data. -
Method Summary
Modifier and TypeMethodDescriptionfloat[][]
Retrieves the color map produced by this color quantizer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface imagingbook.common.color.quantize.ColorQuantizer
findColorIndex, getColorCount, quantize, quantize, quantize
-
Constructor Details
-
MedianCutQuantizer
Constructor, creates a newMedianCutQuantizer
with up to K colors, but never more than the number of colors found in the supplied pixel data.- Parameters:
pixels
- an image as a aRGB-encoded int arrayK
- the desired number of colors (1 or more)
-
-
Method Details
-
getColorMap
Description copied from interface:ColorQuantizer
Retrieves the color map produced by this color quantizer. The returned array is in the format float[idx][rgb], where rgb = 0 (red), 1 (green), 2 (blue) and 0 ≤ idx < nColors.- Specified by:
getColorMap
in interfaceColorQuantizer
- Returns:
- The table of reference (quantization) colors.
-