/K-Means-Color-Clustering

Yet another implementation of K-means for color clustering in images

Primary LanguageMatlab

Introduction

Another implementation of K-means algorithm for color quantization in the images. This one is substantially commented, so some may find it useful.
However, it is slow(even for Matlab) due to inverse mapping. It does not store the cluster assignment of the pixels but calculates the distance from the center of the cluster in every iteration. Therefore, it is not computation efficient.
It does not need additional space, though. As the inverse mapping is computed on the fly, there is no need for storing the clustered pixels.
read_color_raw.m reads .raw color images. readraw reads grayscale .raw in images, which are both used in k_means_Color_Clustering.m. mean_square_error.m computes the euclidean distance between two images by pixel values.

Results

K = 2

Alt text
K = 3

Alt text
K = 4

Alt text
K = 5

Alt text
K = 6

Alt text
K = 7

Alt text
K = 8

Alt text
K = 9

Alt text
K = 10

Alt text