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

where M is the sum of intensive m_i, m_i is the intensive pixel value, x_i and y_i are the location of the pixel in the image, n is the total number of pixels.
Can anyone suggest something like working with multiple loops or how to ignore others when calculating one of them using the same formula?
source
share