This code is implementation of KMeans clustering algorithm in python without the use of any libraries.
- First the tif image is taken and converted to raster using gdal
- The RGB band as stacked together in a single 3D matrix to ease the computation
- Cluster value(N) and iteration(Itr) number is taken as input parameter from user, and after each iteration result is shown to avoid over processing
- N random clusters are assumed for initialisation
- For each Itr:
- N new mean is found assuming euclidean distances
- based on new mean, cluster allotment is done for all points on the basis of minDistance
- Step 5 for repeated for given Itr or till visual result is not achieved whichever is earlier
- For each points based on final cluster allotment, a color is specified and plotted