What are we actually doing here?

In the video he told that at 1:09 min timestamp
"we will iterate over every pixel and see the closet centre for every pixel and replace the new_img pixel with closet one "

but in the for loop we are simply iterating over new_img and putting color value in order of for loop. we are not looking for the closet centre and then replacing

for i in range(new_image.shape[0]):
new_image[i]=color[km.labels_[i]]

hey @Par1hsharma ,
if you check that naa , there is km.labels_
this k is doing that operation of finding the closest cluster.
and hence you get those colors

I hope this helps.

how we are finding the closest cluster here?
km.labels_[I] depends upon ā€˜I’ value it will take km.lables[0] which in turn takes color[km.labels_[0]] . it all depends wheather I is 0 or 1 or 2.

for that thing, you need to once learn about the KNN approach. How does it works and all, if still there is some doubt in that , then tell me i will help you out.

in KNN we find distance but what are we doing here I am not able to understand

assuming that you are good with KNN.
here what we do is , based on the class that KNN predicted we update the colors on actual image.

hence , a simple form of segmentation

Sorry but I am confused what KNN has to do with K-Means

Sorry i mixed it.

In Kmeans , we initially take a n random points from the data provided and based on them classify others according to there distance from the cluster points and update those points.

In this way we get our final color clusters and then using those clusters , we update our image colors as it is done above.