I'm making a C++ application, and I want to quantize the colors in a imported image, using a fixed palette with optional dithering. Ideally, with many dithering algorithms for a user to choose from. This quantized image will then be passed to a later part of the program.

The problem is, I can't find a library that satisfies these conditions. Here are the libraries I've looked at (note, this is my own observations and I may be overlooking stuff):

  • OpenCV
    • I decided that it's WAY overkill for what I'm doing
  • Leptonica
    • http://www.leptonica.org/color-quantization.html
    • Supports quantization (colorquant1.c & colorquant2.c)
      • Supports dithering, not sure which algorithm
      • Doesn't appear to support user-set palette (maybe the static helper pixQuantizeWithColormap()??)
      • Doesn't appear to support color bleed reduction (multiplying error values by a constant <=1 in order to make the algorithm less "bold" when choosing a color for a pixel)
  • Magick++ (ImageMagick)
    • https://www.imagemagick.org/Usage/quantize/
    • https://www.imagemagick.org/Magick++/Image++.html#Image%20Manipulation%20Methods
    • Easy to understand high-level functions
    • Supports quantization
      • Supports Floyd-Steinberg dithering (Image.quantize() w/ quantize- Dither == true)
        • It also supports Bayer (Image.randomThreshold("2x2")), but in B/W only (I know Bayer or some other ordered dithering algorithm definitely has a color version. There's one in GIMP.)
        • ImageMagick itself also supports Riemersma, but it doesn't appear it's implemented in Magick++
      • ImageMagick supports user-set palettes, but this also does not appear to be implemented in Magick++
      • Doesn't appear to support color bleed reduction

So is there a library that fits my purpose? Did I miss something while reading docs? Please note that I'll be using the library for other image processing as well, like cropping and reading individual pixels.


nQuantCpp includes top 6 color quantization algorithms for visual c++ producing high quality optimized images.

As you mentioned about Riemersma, Generalized Hilbert ("gilbert") space-filling curve for rectangular domains of arbitrary (non-power of two) sizes which can dither better than the Hilbert curve visits every point in a square grid with a size of any other power of 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.