Skip to content

KMeans clustering algorithms for image segmentation

Notifications You must be signed in to change notification settings

talis-fb/kmeans_rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KMeans Image Segmentation CLI

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.

Java Version Available

For a Java-based implementation of this project, visit the KMeans Java Repository.

Image Segmentations with Different K Values

To get a concrete example of result of this program...

Base Image
K Image
2
5
10
25
60

Example Workflow

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

Workflow step-by-step

  1. Convert image to CSV:
img-to-csv to-csv input_image.jpg > image.csv
  1. Apply KMeans clustering:
kmeans -K 5 -m parallel < image.csv > segmented_image.csv
  1. Convert CSV back to image:
img-to-csv to-image -o output_image.jpg < segmented_image.csv

How It Works

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.

About

KMeans clustering algorithms for image segmentation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages