Class KMeansQuantizer

  • All Implemented Interfaces:
    ColorQuantizer

    public final class KMeansQuantizer
    extends java.lang.Object
    implements ColorQuantizer
    Uses k-means clustering for color quantization. This tends to yield good results, but convergence can be slow. It is not recommended for large images.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<QColor> quantize​(Multiset<QColor> originalColors, int maxColorCount)
      Quantize the given set of colors, returning a set no larger than maxColors.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • quantize

        public java.util.Set<QColor> quantize​(Multiset<QColor> originalColors,
                                              int maxColorCount)
        Description copied from interface: ColorQuantizer
        Quantize the given set of colors, returning a set no larger than maxColors.

        The intent is to pick a set of colors which are representative of the original color set, but no specific guarantees are made.

        Specified by:
        quantize in interface ColorQuantizer
        Parameters:
        originalColors - the colors in the original image
        maxColorCount - the maximum number of colors to allow
        Returns:
        a quantized collection of colors no larger than maxColors