Skip to main content
. 2019 Mar 14;5(3):38. doi: 10.3390/jimaging5030038
Algorithm 1: Online K-Means clustering algorithm for color-based image segmentation
1: Initialize the ‘k’ number of centroids, C1, C2, C3....Ck with random values.
2: Initialize the counts n1, n2, n3 .... nk to zero.
3: while ‘pixel stream continues’ do
4:  p ← RGB2YCbCr(p)
5:  Match the input pixel, ‘p’, to a single centroid Ci by minimizing the distance pCi2
6:  Increment ni
7:  Update the matching centroid, Ci, using moving average
8: Ci^Ci + (1/ ni)(p − Ci)
9:  Classify the input pixel, ‘p’, as ‘i’.
10: end