A Rust-based command-line tool implementing various KMeans clustering algorithms for image segmentation.
It covers multiple implementations of the KMeans algorithm, both serial and parallel. For perfomance comparison and study purposes.
This tool is designed to work seamlessly with the Image to CSV CLI project. Use the img-to-csv tool to convert an image to CSV, process it with kmeans for segmentation, and convert the result back to an image.
For a Java-based implementation of this project, visit the KMeans Java Repository.
To get a concrete example of result of this program...
Base Image |
---|
K | Image |
---|---|
2 | |
5 | |
10 | |
25 | |
60 |
As the tool uses STDIN and STDOUT for communication, you can use pipes and redirection to integrate it with img-to-csv
.
This example processes an input_image.jpg image file and creates another image file called output_final_image.png, applying KMeans image segmentation with K equals 5:
img-to-csv to-csv input_image.jpg | kmeans -K 5 -m parallel | img-to-csv to-image -o output_final_image.png
- Convert image to CSV:
img-to-csv to-csv input_image.jpg > image.csv
- Apply KMeans clustering:
kmeans -K 5 -m parallel < image.csv > segmented_image.csv
- Convert CSV back to image:
img-to-csv to-image -o output_image.jpg < segmented_image.csv
The tool processes CSV files where each line represents a pixel's coordinates (X and Y) and RGB values:
X:Y R G B
- Input: CSV format from STDIN.
- Output: CSV format to STDOUT with modified RGB values representing cluster centers.