This might be worth checking https://github.com/pixelwhipped/QuantizeFast.
It kind of looks at dominant colors as it keeps the frequency and index of colors as it merges them down