Ask Your Question

Revision history [back]

I'm not sure to understand your question.

You cannot set initial centers in k-means. But you can set initial labels. It means that if you know intial labels then you know initial centers. You can do like this :

  1. set initial center
  2. compute distance between centers and data. Set data label equal to nearest center
  3. call kmean with falg KMEANS_USE_INITIAL_LABELS

I'm not sure to understand your question.

You cannot set initial centers in k-means. But you can set initial labels. It means that if you know intial labels then you know initial centers. You can do like this :

  1. set initial center
  2. compute distance between centers and data. Set data label equal to nearest center
  3. call kmean with falg KMEANS_USE_INITIAL_LABELS

I think you can use this sample : replace Mat points(sampleCount, 1, CV_32FC2), labels; by Mat points(sampleCount, 1, CV_32FC2), labels(sampleCount, 1,CV_32SC1); and in loop

label.rowRange(k*sampleCount/clusterCount, k == clusterCount - 1 ? sampleCount :(k+1)*sampleCount/clusterCount) =k;

I haven't tested..