Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;

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?

share|improve this question
need help with this please look into this… – user32234 Jun 22 '13 at 14:51
up vote 7 down vote accepted

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

share|improve this answer
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") – bummzack Aug 26 '11 at 22:57
oh wow. I didn't even know about flood-filling. thanks. – TravisG Aug 26 '11 at 23:00

Check this: After detecting blobs just apply marching squares alg to get the margins of each blob.

Bye Lo

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.