c - Linear algorithm to fill a contour -
i trying make algorithm fill contour in linear complexity. know such algorithm exists. i've read somewhere has number of crossings, there special case haven't had great luck in solving yet.
so far have tried using following algorithm. note can't access previous elements (to left) because will/may overwritten:
for (int y = blob->miny; y < blob->maxy; ++y) { int numberofbordercrossings = 0; unsigned int nextelem = 0; unsigned int nextnextelem = 0; (int x = blob->minx-1; x < blob->maxx-1; ++x) { nextelem = cv_image_elem(labelimg,unsigned int,y,x+1); nextnextelem = cv_image_elem(labelimg,unsigned int,y,x+2); if (cv_image_elem(labelimg,unsigned int,y,x) != label) { if (nextelem == label && nextnextelem != label) ++numberofbordercrossings; else if (numberofbordercrossings%2) cv_image_elem(labelimg,unsigned int,y,x) = label; } } }
the result following. input right (all non-black pixels must copied), , erroneous output left. note again have contour of image right (not rendered).
it appears you're looking general polygon filling algorithm. line crossing counting algorithm break hits single points , horizontal , vertical lines. have @ quickfill possible alternative.
Comments
Post a Comment