K-means groups the photo's pixels into k clusters. The algorithm first makes a guess at the k dominant colors. It then iteratively assigns pixels to clusters based on color distances and updates each cluster's average color. When the clusters no longer update, the original image is redrawn with only k colors. Read more on GitHub
or contact the author.