Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to detect discontinuity in object boundaries

i have shapes in image having background. i want to remove background from it for that i made logic which works ok for shapes having full boundary around them but cant work if their is discontinuity or leakage in boundary . so am wondering how can we find discontinuity in shape boundary so that my code not erase pixel it that area

example

image with full boundary .

image description

so when i have image like this which have no leakage in boundary i run flood fill algo on image which return me all green pixel locations and i turn their alpha to zero due to which i am left with these two shapes and green background is removed.

image description

but sometime i have images in which shapes boundary is not complete it have somewhere discontinuity in it , so am wondering how i can detect that shape in image outer boundary is not complete so that i not use flood fill method to remove background because i do not want to remove anything inside shape , alternatively i remove background by looping though pixels from left to right , right to left , top to bottom , bottom to top and check for pixel color if not equal to red then remove it else skip due to which background is remove from all most all image from all sides. but for this alternative method i need to know that their is discontinuity in shape boundary.