Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 906
Morteza Milani Avatar asked Nov 16 '25 07:11

Morteza Milani


2 Answers

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#

like image 123
Aaron Digulla Avatar answered Nov 18 '25 21:11

Aaron Digulla


The simplest approach is to use a morphological technique called closing. This will work only if the gaps in the lines are quite small in relation to how close the different lines are to each other.

How you choose the structuring elemt to perform the closing can also make performance better or worse.

The Wikipedia article is very theoretical (or mathematical) so you might want to turn to Google or any book on Image Processing to get a better explanation on how it is done.

like image 32
Hannes Ovrén Avatar answered Nov 18 '25 20:11

Hannes Ovrén



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!