protected void updateClusters ( ) { for ( int i = 0 ; i < clusters . size ; i ++ ) { clusters . data [ i ] . reset ( ) ; } int indexPixel = 0 ; for ( int y = 0 ; y < input . height && ! stopRequested ; y ++ ) { int indexInput = input . startIndex + y * input . stride ; for ( int x = 0 ; x < input . width ; x ++ , indexPixel ++ , indexInput ++ ) { Pixel p = pixels . get ( indexPixel ) ; // convert the distance each cluster is from the pixel into weights p . computeWeights ( ) ; for ( int i = 0 ; i < p . clusters . size ; i ++ ) { ClusterDistance d = p . clusters . data [ i ] ; d . cluster . x += x * d . distance ; d . cluster . y += y * d . distance ; d . cluster . totalWeight += d . distance ; addColor ( d . cluster . color , indexInput , d . distance ) ; } } } // recompute the center of each cluster for ( int i = 0 ; i < clusters . size ; i ++ ) { clusters . data [ i ] . update ( ) ; } }
Update the value of each cluster using Maximization step .