This Processing sketch demonstrates K-means clustering for visual abstraction of images. It allows users to interactively adjust the number of clusters and toggle pixel sorting within clusters.
- K-means clustering for image abstraction
- Interactive slider to adjust the number of clusters (k)
- Option to sort pixels within clusters based on brightness
- Real-time visualization of clustering results
- Processing 3 or later
- Clone this repository or download the sketch files.
- Open the
k_means_clustering_sketch.pde
file in Processing. - Place your input image (named
IMG_5748_1080x1080.png
) in thedata/
folder. - Run the sketch.
- Use the slider at the bottom of the window to adjust the number of clusters (k).
- Press “S” or “s” to toggle pixel sorting within clusters.
k_means_clustering_sketch.pde
: Main sketch file containing the K-means clustering implementation and visualization code.Slider.pde
: Class file for the interactive slider used to adjust the number of clusters.data/IMG_5748_1080x1080.png
: Sample input image (replace with your own image).
This project is open-source and available under the MIT License.