Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
need help with this please look into this stackoverflow.com/questions/17232672/… –  user32234 Jun 22 '13 at 14:51
add comment

3 Answers

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
1  
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
add comment

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

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.