title: How do I find the connected components in a binary image?
body: <p>I am looking for an algorithm to find all connected components in my binary image.</p>
  
  <p>If we think of the image like a matrix, it looks like:</p>
  
  <pre><code>[ 0 0 0 0 ...
    0 0 0 0 ...
    0 1 1 1 ...
    0 1 0 1 ...
    0 1 0 0 ...
    ...
  ]
  </code></pre>
  
  <p>I would like to find the all the ones that are touching (diagonally, as well). In this example, there is only one component - but there may be hundreds of unique components in an image.</p>
  
  <pre><code>Image =&gt; ALGORITHM =&gt; [ [(x,y)], ... ] 
                        # list of lists of coordinates (each shape is a list)
  </code></pre>
  
  <p>I have looked at the <a href="http://en.wikipedia.org/wiki/Connected-component_labeling" rel="noreferrer">two pass labelling</a> algorithm on Wikipedia, but I don't believe it returns me the actual components - it just labels the distinct components. (Or is this one and the same?)</p>
  
  <p>If possible, this should be able to run in real-time against a video stream.</p>