Kmean implementation using level of gray [slow]