# how to get new center points in kmeans

hi,

trying to get new center points of newly created clusters with kmeans function. applying kemeans function as below;

```
kmeans(tmpsp[1], 4, labels, TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 10, 1.0/*CV_TERMCRIT_ITER, 1, 1.0*/), 3, KMEANS_RANDOM_CENTERS, newCenters);
```

and this is tmpsp[1] dataset (actually it is an image with the size of 91x53, and the type is CV_32F);

this is labels, it contains numbers from 0 to (cluster count-1), it is in size of 1x53;

and this is newCenters, matrix in size of 94x53;

1) how can i get centroids of found clusters? i need accurate x and y points for each clusters. 2) how can I give initial centroids?

thanks.

what are you trying to achieve ?

kmeans will cluster

row-vectors, not 2d (hmm points?circles?neighbourhoods?).(btw, newCenters should come out as matrix in size of 91x4, no?)

did you want the center points of the 4 black areas ?

nope, trying to seperate white area in 4 section and find theirs centroids. however, as i understood, kmeans algorithm takes the 2D matrix as a complete feature vector set. in example, in my question 2D vector has been given as a parameter to kmeans function, and it is 91x53 matrix. so, kmeans recognizes it as 53 samples with 93 features and when it finishes its job, gives me newcenters which are calculated by looking 93 features of all 53 samples in complete vector set. that is why i'm getting newcenters matrix in sizes of 91x4 when i request for 4 clusters. if i can get the coordinates of all pixels whose value is 255, put those coordinates to a matrix and give it to kmeans, it will calculate me new points as well.

so here is a new question; how can i get coordinates of all pixels whose value is 255 and write them into a new Mat object?