Extremely simple implementation of KMeans clustering algorithm
First, you create virtual environment and install package. I already tested it and it works well in my environment (Windows 10).
conda create python=3.8 -n kmeans
conda activate kmeans
pip install numpy matplotlib
python kmeans.py
For your information, I attached a help message for better usage.
usage: kmeans.py [-h] [--k K] [--input INPUT]
optional arguments:
-h, --help show this help message and exit
--k K The number of centroid (default to 50)
--input INPUT The filepath for input image (default to os.path.join("res", "input.jpg"))
I just downloaded an image from the image search result in Google with keyword "Detroit become human kara". This image could raise an copyright issue. If it occurs, I will change the other copyright-free image, but for now, I want to keep this image because this image makes me passionate to implement this code.
The original source: https://www.syfy.com/syfywire/video-game-heroine-of-the-month-kara-from-detroit-become-human
K | Result | K | Result |
---|---|---|---|
2 | ![]() |
3 | ![]() |
4 | ![]() |
5 | ![]() |
6 | ![]() |
7 | ![]() |
8 | ![]() |
9 | ![]() |
10 | ![]() |
50 | ![]() |
Please open an issue or send an e-mail if you have trouble with this code or find a bug.