My blogpost on K-means clustering has the highest number of views, so people are probably interested in it. Sadly enough I lost the source code of the K-means action a while ago. Last week I needed an external harddisk to make a back-up of some files. There was already some content on the disk. I found quite some pieces of code including the K-means code. Although it is quite simple code operating on (if I remember correctly 8-bit) greyscale images, it might give some insights in how to do this.
The whole code file is presented below. For more information you can view my earlier blogpost on K-means clustering.
The source code might not be completely visible. It can be viewed in a blank screen here. As mentioned in the replies to this post, I forgot to add the ClusterClass. It can be viewed in a blank screen here.