I'm having difficulty understanding what the labels
and centres
are in kmeans, specifically OpenCV's kmeans()
function.
I understand that kmeans will find k clusters in a data sample. And that the centres
parameter tells me the centre/centroid of each cluster.
But what are the labels and when I tried to inspect my centres
it said I have 2 rows and 3 columns but I ran kmeans with 6 clusters - Shouldn't `centres' then have 6 rows (1 for each cluster)? Finally inspecting centres' values is outputting float values - shouldn't they be indexes (ints)? As in indexes of the data sample array.
How the heck can I get the cluster centres (in data coordinates) after running kmeans? Ultimately I'm trying to find the most common colours - so the cluster centres I assume would be BGR/HSV/Lab values depending on my Mat type?
kmeans(collapsedImage, 6, labels,
TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 10, 1.0),
3, KMEANS_PP_CENTERS, centres);
printf("rows: %d, cols: %d", centres.rows, centres.cols);
// outputs 'rows : 2, cols : 3'
for (int i = 0; i < centres.rows; i++) {
for (int j = 0; j < centres.cols; j++) {
std::cout << centres.at<float>(i, j) << " ";
}
std::cout << std::endl;
}
// Outputs: Why are these floats???
// 1.48938 0.578623 0.464539
// 242.628 131.947 80.5347