Class MedianCutQuantizer

java.lang.Object
imagingbook.common.color.quantize.MedianCutQuantizer
All Implemented Interfaces:
ColorQuantizer

public class MedianCutQuantizer extends Object implements 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
  • Constructor Details

    • MedianCutQuantizer

      public MedianCutQuantizer(int[] pixels, int K)
      Constructor, creates a new MedianCutQuantizer 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 array
      K - the desired number of colors (1 or more)
  • Method Details

    • getColorMap

      public float[][] 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 interface ColorQuantizer
      Returns:
      The table of reference (quantization) colors.