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 »

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 »

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

Re: Remove underlines from image for ocr

Post by snibgo »

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 »

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: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove underlines from image for ocr

Post by snibgo »

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