blobs and holes (vectorizing an image)

greetings,

i’m looking at ways to vectorize an image. working with opencv seemed to be a good place to start - quantizing the image into different levels of brightness and then doing blob detection on each level. but then i ran into problems matching holes with their blobs.

i figured that if i could match a blob with its hole then i could use ofNextCountour() to draw the shapes with their holes intact.

is there a best method for doing this? the contour finder doesn’t report back which holes are connected with which shapes … and looping through all of the holes to match them with in the shape bounds isn’t terribly efficient.

also, if anybody has any recommendations for libraries that vectorize images, please pass them on.

thanks++,

jeremy

there’s a number of interesting arguments to the OpenCV’s findContours method:

http://www710.univ-lyon1.fr/~bouakaz/OpenCV-0.9.5/docref/OpenCVRef-ImageProcessing.htm#decl-cvFindContours

in particular:

mode: Retrieval mode.

* CV_RETR_EXTERNAL retrives only the extreme outer contours
* CV_RETR_LIST retrieves all the contours and puts them in the list
* CV_RETR_CCOMP retrieves all the contours and organizes them into two-level hierarchy: top level are external boundaries of the components, second level are bounda boundaries of the holes
* CV_RETR_TREE retrieves all the contours and reconstructs the full hierarchy of nested contours

you might have some luck if you use this function directly, i don’t think this complexity is available in the oF contour finder. working with OpenCV directly can be a pain though, there’s lots of housekeeping to think about… or, you could just edit your local copy of the contour finder; or at least make a copy of it, rename it and edit and use that.

yo damien,

thanks for the helpful tip. i found a few good examples of how to create tree structures using the data created by cvFindContours, including this one (which includes source).

http://jmpelletier.com/category/tutorials/

i created a little addOn with an example for folks who might be interested in distinguishing between shapes and holes. not sure if it’s worth posting on the addOns page, so I’ve just uploaded it to my site for the time being.

http://www.mantissa.ca/oF/ofxContourTreeFinder.zip

jeremy

yey! it’s workin! (of 007 osX) thank you @mantissa very helpful

greetings ascorbin

hm, after some testing sadly its not working for all images, sometimes it crashes with EXC_BAD_ACCESS cause of addElementToTreeStucture(parent_ptr, NULL, true, minArea, maxArea);
dont know why: owi_1.gif is working, owi_2.gif is not.