Class QuantizerWsmeans

java.lang.Object
org.glavo.monetfx.internal.quantize.QuantizerWsmeans

public final class QuantizerWsmeans extends Object
An image quantizer that improves on the speed of a standard K-Means algorithm by implementing several optimizations, including deduping identical pixels and a triangle inequality rule that reduces the number of comparisons needed to identify which cluster a point should be moved to.

Wsmeans stands for Weighted Square Means.

This algorithm was designed by M. Emre Celebi, and was found in their 2011 paper, Improving the Performance of K-Means for Color Quantization. https://arxiv.org/abs/1101.0395

  • Method Details

    • quantize

      public static Map<Integer,Integer> quantize(int[] inputPixels, int[] startingClusters, int maxColors)
      Reduce the number of colors needed to represented the input, minimizing the difference between the original image and the recolored image.
      Parameters:
      inputPixels - Colors in ARGB format.
      startingClusters - Defines the initial state of the quantizer. Passing an empty array is fine, the implementation will create its own initial state that leads to reproducible results for the same inputs. Passing an array that is the result of Wu quantization leads to higher quality results.
      maxColors - The number of colors to divide the image into. A lower number of colors may be returned.
      Returns:
      Map with keys of colors in ARGB format, values of how many of the input pixels belong to the color.