Remove underlines from image for ocr

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
wineismine
Posts: 6
Joined: 2017-10-22T04:06:07-07:00
Authentication code: 1151

Remove underlines from image for ocr

Post by wineismine » 2018-06-20T00:40:17-07:00

I need to remove lines from the following image without affecting the characters
Image

Code: Select all

magick 21.gif -monochrome ( +clone -negate -statistic median 219x1 ) -compose lighten -composite q1.png
To make it more clearI dont want my image to have gaps which are shown in the image below, due to the line removal using the above code
Image

wineismine
Posts: 6
Joined: 2017-10-22T04:06:07-07:00
Authentication code: 1151

Re: Remove underlines from image for ocr

Post by wineismine » 2018-07-04T05:42:38-07:00

anyone?

snibgo
Posts: 10563
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove underlines from image for ocr

Post by snibgo » 2018-07-04T06:10:19-07:00

It can be done, but I can't see an easy way.

Each pixel that is removed may have had neighbours in three positions on the previous row (up, up-left and up-right), and neighbours in three positions on the following row.

For some combinations of neighbours, you want to replace the pixel that was removed. For others, you don't.

I don't have enough time to work out the details.
snibgo's IM pages: im.snibgo.com

wineismine
Posts: 6
Joined: 2017-10-22T04:06:07-07:00
Authentication code: 1151

Re: Remove underlines from image for ocr

Post by wineismine » 2018-07-04T07:20:26-07:00

snibgo wrote:
2018-07-04T06:10:19-07:00
It can be done, but I can't see an easy way.

Each pixel that is removed may have had neighbours in three positions on the previous row (up, up-left and up-right), and neighbours in three positions on the following row.

For some combinations of neighbours, you want to replace the pixel that was removed. For others, you don't.

I don't have enough time to work out the details.
could you give me some example codes to try?

snibgo
Posts: 10563
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove underlines from image for ocr

Post by snibgo » 2018-07-04T11:46:53-07:00

Another approach is Mending broken lines, but mask this so mending occurs only where horizontal lines have been removed.
snibgo's IM pages: im.snibgo.com

Post Reply