3

how to make marching squares proceed after it finds the first contour?

the contours in the image am working on are going to change quite often and because am in an embedded environment(android/ios) i would like a fast performance solution above all. and using an external library isn't an option.

i tried connected component labeling but never got it to work as i have a PNG which isn't black and white (isn't thresholded) and if am not mistaken the CCL only works on black and white (binary) images.

i thought about saving the blob information to another vector and check if the newly found pixels fall within the earlier found blobs but i don't think that's fast enough as the vector gets filled with more and more blobs it gets more and more expensive to check every blob inside the vector.

which leaves me with my almost finished current approach which is erasing the contours i find and repeat until there's nothing left? but that's my currently used approach which seems expensive too.

and if there is no fast solution then can anyone suggest a different approach...even if that means a different algorithm.

Mark1: i chose marching squares because i only need the outline of the contours even if there are holes in theme.

Joseph
  • 1,458
  • 15
  • 20
  • May be there is a terminology problem... The "marching squares" algorithm finds all the contours at the same time (including holes, see https://en.wikipedia.org/wiki/Marching_squares). Given an image what kind of output are you looking for? A general polygon (i.e. not necessarily connected or simply connected) for each of the values that is present in the image? – 6502 Dec 08 '15 at 20:25
  • apparently you're right and there are two different distinct implementations for this algorithm and the one that am using right now only works on images with one shape in it and here is where i got it from : http://www.emanueleferonato.com/2013/03/01/using-marching-squares-algorithm-to-trace-the-contour-of-an-image/ that's the implementation that am currently using and its different from the wiki article above. so is there any c++ implementation of the algorithm that is mentioned in the wiki article which extracts multiple shapes at once. – Joseph Dec 08 '15 at 20:58
  • i managed to find a good fast implementation that extracts all the geometry at One pass!! ... so i guess it's Solved then. – Joseph Dec 09 '15 at 12:10
  • I keep getting reminded of https://xkcd.com/979/ everytime I see this kind of question (open, but solved). – syockit Jan 08 '20 at 12:57

1 Answers1

0

i solved my problem by using an implementation of the marching squares algorithm that i found in the chipmunk2d physics library.

Joseph
  • 1,458
  • 15
  • 20