kmeans cluster radius

asked 2015-04-09 11:26:55 -0600

antithing gravatar image

Hi, I have discovered kmeans, and am using it like this:

 Mat labels, centers;

int  attempts = 50, clusterCount = 4, flags = cv::KMEANS_PP_CENTERS; 
TermCriteria tc;


kmeans(centroids, clusterCount, labels, tc, attempts, flags, centers);

BUT, as it will run in a video stream, the number of clusters that i want will change as it picks up more points of interest. Is there a way to use radius from cluster centre to search instead of number of clusters?

thanks.

edit retag flag offensive close merge delete

Comments

1

I think you should start by what are you trying to do, maybe there is some other approaches that fit better than kmeans...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-04-10 02:51:19 -0600 )edit

Hi, I am trying to identify the separate clusters in images like this :

http://i58.tinypic.com/wwdw0l.jpg

So that I end up with this:

http://i59.tinypic.com/2dm9gtl.jpg

Yesterday someone suggested kmeans, which works on the still frame, but when it is a video stream, the number of clusters needs to change automatically.

antithing gravatar imageantithing ( 2015-04-10 03:21:31 -0600 )edit

So applying the kmeans on each frame is "wrong" because you have set clusterCount to 4? You'll need some sort of detector for the number of clusters...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-04-10 04:05:08 -0600 )edit

exactly. I need a function that will find a new cluster as it appears in frame, and make it a new cluster.

Is kMeans not what i need for this? Or would i use it in conjunction with something else? What sort of detector would you recommend?

thanks for your help

antithing gravatar imageantithing ( 2015-04-10 04:09:07 -0600 )edit
2

Have you seen this? Have you done it in another way? Why do you want to change it? Maybe applying kmeans in a loop and detecting the best number of clusters is the way; but maybe this is not going to be fast enough.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-04-10 04:17:41 -0600 )edit

thanks! I am unsure how to detect the best number of clusters. Will read through that wiki again and try to understand it... Possibly kMeans is not what i want though, as clusters will be constantly in and out of frame.

Is there any other function that searches for clustering in a similar way, or would you suggest another approach?

antithing gravatar imageantithing ( 2015-04-10 04:26:42 -0600 )edit
1

Maybe adjusting number of clusters based on the standard deviation in each cluster if you do a kmeans with clusterCount+1 and clusterCount-1?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-04-10 04:31:17 -0600 )edit

This may help too

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-04-10 04:33:21 -0600 )edit

sorted. using the 'rule of thumb' from that wiki page, then looping and adding one each time. thanks for your help!

                    int cNumber = sqrt(centroids.size() / 2);

                    if (expectedClusterSize != actualClusterSize)
                        {
                    cNumber = (cNumber + 1);
                            kmeans(centroids, cNumber, labels, tc, attempts, flags, centers);  
                           }
antithing gravatar imageantithing ( 2015-04-10 05:01:54 -0600 )edit

...obviously will only work if all clusters are the same size.

antithing gravatar imageantithing ( 2015-04-10 05:04:01 -0600 )edit