This repository is part of a comparative study on concurrent programming strategies for K-Means clustering applied to image segmentation. The study explores and contrasts different concurrency models and techniques in Rust and Java, analyzing their performance, synchronization mechanisms, and runtime characteristics.
This project implements various K-Means clustering algorithms for image segmentation in both Rust and Java, focusing on different parallelization strategies. The goal is to evaluate the efficiency and scalability of each approach when applied to image processing and study purposes.
It's used the Image to CSV CLI project to convert an image to CSV, process it with kmeans for segmentation, and convert the result back to an image.
To get a concrete example of result of this program...
|
|
In the Java implementation, multiple strategies were employed to handle concurrency, including:
-
Thread Synchronization Techniques: Various approaches such as locks, synchronized blocks, and atomic operations were explored.
-
Virtual Threads vs. Native Threads: Performance was compared between traditional Java threads and virtual threads introduced in newer Java versions.
-
Performance Profiling and Benchmarking:
-
JMH (Java Microbenchmark Harness): Used to benchmark different concurrency approaches.
-
JMC (Java Mission Control): Employed for detailed profiling and runtime analysis.
-
Java Profiling Tools: Used to inspect thread behavior, contention, and memory usage.
-
In the Rust implementation, different concurrency models were tested:
-
Tokio Runtime: An asynchronous runtime for handling concurrent tasks.
-
Rayon: A data parallelism library optimized for multi-threading.
-
Rust Standard Library (std::thread): A more traditional multi-threading approach.
Each runtime was analyzed based on execution speed, CPU utilization, and memory consumption.
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.csvThe 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.
You can check the complete study HERE.





