Get center coordinate of grid blob

时间:2015-07-28 15:49:17

标签: python numpy k-means

I have a 2d grid that changes every hour with this layout:

enter image description here

The gridshape is about 765*700 and it contains several of this data clusters. Now we need to find those clusters and get the center pixel coordinate of it.

The problem with K-means is that we need to specify a number of cluster, but that number should be detected on some way. Now we have some little script to detect those clusters, but the problem is that it detects some of the clusters more then one time.

enter image description here

for x in range(0,765):
    for y in range(0,700):
        if data_array[x,y] > 0:                                                   
            if data_array[x-1][y-1] > 40 and data_array[x+1][y+1] > 40:           
               if data_array[x-2][y-2] > 40 and data_array[x+2][y+2] > 40:        
                    if data_array[x-3][y-3] > 40 and data_array[x+3][y+3] > 
                        xp.append(y)        
                        yp.append(x)        
                        value.append(data_array[x][y])

We need for each of those clusters the center pixel coordinate's X and Y. Im sure this is not the best way to do this, what should be the best way to start with this ? For example the first image the marked value should be detected as center of the cluster, and return the coordinates of this: 346*558

0 个答案:

没有答案