The KMeans class takes an image, clusters it using the K-Means algorithm and gives a variety of outputs. It also includes an elbow method implementation for automatically choosing the optimal number of clusters(K).
1.Run the jupyter notebook (imageprocessingkmeans.ipynb) and upload an image and the kmeans class OR
- Import KMeans
from kmeans import KMeans
- Initialize a KMeans class with 3 dimensions(R,G,B)
km = KMeans(3)
- Use elbow method to find optimal K value
km.k, km.inertias = km.elbow(<maxK>, <maxIterations>, <filePath>)
#Or set km.k manually without using the elbow method
4.Train the model
km.train(<maxIterations>)
5.Generate desired output
#Use any of the following
km.graphInertias()
km.outputGraph()
km.outputImage()
km.outputImageAlternate()