9

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?

TravisG
  • 4,402
  • 4
  • 36
  • 59
  • need help with this please look into this http://stackoverflow.com/questions/17232672/drawing-isotherm-linesor-contour-using-java-given-specific-points –  Jun 22 '13 at 14:51

3 Answers3

7

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

Adam
  • 7,346
  • 19
  • 25
  • 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
2

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

LMFRaptor
  • 21
  • 1
1

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.

Abe K
  • 11
  • 1