title: Finding clusters of mass in a matrix/bitmap
body: <p>This is in continuation with the question posted here:
  <a href="https://stackoverflow.com/questions/408358/finding-the-center-of-mass-on-a-2d-bitmap">Finding the center of mass on a 2D bitmap</a> which talked about finding the center of mass in a boolean matrix, as the example was given.</p>
  
  <p>Suppose now we expand the matrix to this form:</p>
  
  <pre><code>0 1 2 3 4 5 6 7 8 9
  1 . X X . . . . . .
  2 . X X X . . X . .
  3 . . . . . X X X .
  4 . . . . . . X . .
  5 . X X . . . . . .
  6 . X . . . . . . .
  7 . X . . . . . . .
  8 . . . . X X . . .
  9 . . . . X X . . .
  </code></pre>
  
  <p>As you can see we now have 4 centers of mass, for 4 different clusters.</p>
  
  <p>We already know how to find a center of mass given that only one exists, if we run that algorithm on this matrix we'll get some point in the middle of the matrix which does not help us.</p>
  
  <p>What can be a good, correct and fast algorithm to find these clusters of mass?</p>