The problem is that I need a simplified version of algorithm, which can calculate centroid of several white contours in a binary image. For example, if there is only one white contour, coordinates Xc and Yc of the contour center are calculated using formula:

where M is the sum of intense m_i, m_i is the pixel intense value, x_i and y_i are pixel location on the image, n is the total number of pixels.

Can anyone suggest something similar to work with several contours, or how to ignore others while calculating one of them using same formula?

## Best Solution

Use some algorithm called connected component labeling first to separate the different blobs. This will assign a unique ID to each region. Then, you can compute a centroid per blob.