Coloring an image with 'K' Colors using K-Means Coloring. Here we implement K-Means Clustering by using only basic Numpy operations.
It refers to reducing the number of colors used to represent an image. We color the image in 'k' number of colors by using K-Means Clustering.
- Take an input image with the desired number of colors (k) and add the threshold of when to stop updating.
- Randomly initialize the centers of the Clusters.
- Calculating distance of each point w.r.t each Centroid and Classifing the Points to the corresponding Centroid.
- Store all points in terms of the Centroid to which they are assigned.
- Recompute the Mean of each Centroid
- Paint the image with the Mu value of each Cluster to the corresponding pixel value.
We consider an image as below and apply the program on this image to color the image with 3, 5, 10 and 20 colors.
Baboon (Original Image)
3 Colors
5 Colors
10 Colors
20 Colors