9
\$\begingroup\$

Principally, this is a follow-up-question to a problem from a few weeks ago, even though this is about the algorithm in general without application to my actual problem.

The algorithm basically searches through all lines in the picture, starting from the top left of it, until it finds a pixel that is a border. In pseudo-C++:

int start = 0;
for(int i=0; i<amount_of_pixels; ++i)
{
   if(pixels[i] == border)
   {
      start = i;
      break;
   }
} 

When it finds one, it starts the marching squares algorithm and finds the contour to whatever object the pixel belongs to.

Let's say I have something like this:

enter image description here

Where everything except the color white is a border.

And have found the contour points of the first blob:

enter image description here

For the general algorithm it's over. It found a contour and has done its job. How can I move on to the other two blobs to find their contours as well?

\$\endgroup\$
1

3 Answers 3

7
\$\begingroup\$

Could you simply erase the polygon it's found by drawing it in the background colour and repeat until there's nothing left?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ That's how it should be done. Flood-fill the found element with the background (or another color) and continue the search (you can continue at the point where you found the first "match") \$\endgroup\$
    – bummzack
    Aug 26, 2011 at 22:57
  • \$\begingroup\$ oh wow. I didn't even know about flood-filling. thanks. \$\endgroup\$
    – TravisG
    Aug 26, 2011 at 23:00
2
\$\begingroup\$

Check this:

http://en.wikipedia.org/wiki/Connected-component_labeling After detecting blobs just apply marching squares alg to get the margins of each blob.

Bye Lo

\$\endgroup\$
1
\$\begingroup\$

why not save the blob information to another array and check if the newly found pixels fall within the bounding box of the earlier blob? Some more manipulation will be required to deal with blobs below the centriod of the earlier blob and which fall within the bounding box.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .