3
votes

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:

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?

2
Be careful, your normalization should be over sum(m_i), NOT over M.Geoff
I've found this formula on the imageprocessing book. I have'nt noticed until you mentioned that it is wrong. :))user3029227
Can you tell us a bit more about your problem? Depending on your environment there may be some libraries / simplifications that may be applicable. Maybe show and image, and what code you have?Geoff
Actually, I think M probably is defined as the total weight. (I was confusing it with n.)Geoff
I don't need code it is for a paper. Environment is two white circles in black space. Binary image, where is no noise.user3029227

2 Answers

2
votes

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.

1
votes

You can use k means algorithm with varying k values which minimum squared error . Finding connected components can help you get the maximum blobs in the image but is susceptible to noise but it is upper bound for the total contours present. After calculating clusters using k means it is trivial to calculate the centroids of the contours.