CIKMeans Filter Sample Code Walk Through

CIKMeans filter “creates a palette of the most common colors found in the image”. It does so by applying K-means clustering algorithm to partition all colors contained within the image (clipped by the rectangle you specified) into K clusters and produces K colors on its output where each color is the mean color (centroid) of the corresponding cluster.
In practice the filter is hardly used on its own. The most common use case is to use its output as an input to other filters, such as CIPaletteCentroid  and CIPalettize filters.