Search code examples
image-processingbitmapraster

How to detect and correct broken lines or shapes in a bitmap?


I want to find an algorithm which can find broken lines or shapes in a bitmap. consider a situation in which I have a bitmap with just two colors, back and white ( Images used in coloring books), there are some curves and lines which should be connected to each other, but due to some scanning errors, white bits sit instead of black ones. How should I detect them? (After this job, I want to convert bitmaps into vector file. I want to work with potrace algorithm).

If you have any Idea, please let me know.


Solution

  • Here is a simple algorithm to heal small gaps:

    First, use a filter which creates a black pixel when any of its eight neighbors is black. This will grow your general outline.

    Next, use a thinning filter which removes the extra outline but leaves the filled gaps alone.

    See this article for some filters and parameters: Image Processing Lab in C#