Horizontal and Vertical Line Removal

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
MkumarD

Horizontal and Vertical Line Removal

Post by MkumarD » 2010-03-02T12:17:11-07:00

Dear Guys,

First of all I need to thank everyone who contributes their knowledge to develop this awesome package ImageMagick.

I'm new to image handling and am currently developing an Image based DataEntry application, In this process I need to remove all the Horizontal lines and vertial(some cases) lines from the Tiff Image. Am using ImageMagick to manipulate images and this is really good.

Is their any method in ImageMagick to remove the lines from Image File?

Any suggestions would be appreciated.

Thanks in advance
Muthukumar D

User avatar
magick
Site Admin
Posts: 10698
Joined: 2003-05-31T11:32:55-07:00

Re: Horizontal and Vertical Line Removal

Post by magick » 2010-03-02T12:25:01-07:00

See http://www.imagemagick.org/Usage/morphology/. A thinning algorithm may work for this problem.

MkumarD

Re: Horizontal and Vertical Line Removal

Post by MkumarD » 2010-03-02T12:41:58-07:00

Thanks for the response, I will go through this.

Meanwhile could you please give an example for this.

Thanks
Muthukumar D

User avatar
fmw42
Posts: 22232
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Horizontal and Vertical Line Removal

Post by fmw42 » 2010-03-02T14:47:38-07:00

it would be best for you to provide a link to one of your images, so we can see the exact nature of the problem and then describe what you would like removed or what you want preserved.

Here is a simple example of the morphologic filter called hit or miss, which Anthony will be building into his -morphology function that is under development now.

lines at various directions:

Image

v=0.333333
convert lines.gif -convolve "0,$v,0,0,$v,0,0,$v,0" -threshold 99% lines_vertical.gif

Image

Evadido

Re: Horizontal and Vertical Line Removal

Post by Evadido » 2010-03-17T05:28:37-07:00

Hi,

I'm looking too for a way to remove lines from images, as a step for preprocessing it for ocr. I tried the command you supplied with several bw images (inverting colors and so), and it seems to do nothing: no error, and the resulting image is the same as the original.

Is there another way to try it?

Thanks in advance

Bonzo
Posts: 2863
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Horizontal and Vertical Line Removal

Post by Bonzo » 2010-03-17T05:49:53-07:00

What version of Im are you using, how are you running the command, can you provide an image ?

User avatar
fmw42
Posts: 22232
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Horizontal and Vertical Line Removal

Post by fmw42 » 2010-03-17T09:22:04-07:00

-convolve was broken for a few releases between about 6.5.9.5 and 6.6.0.3. I believe it was fixed in 6.6.0.4 and definitely by 6.6.0.5

Evadido

Re: Horizontal and Vertical Line Removal

Post by Evadido » 2010-03-17T09:55:27-07:00

I'm running version 6.5.1-0 over Ubuntu. It is not in the range it was broken.

I just copied & pasted the two command lines changing the file names.

An example image (original and inverted):

http://protalia.com/prueba.pnm
http://protalia.com/prueba2.pnm

Thank you a lot

User avatar
fmw42
Posts: 22232
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Horizontal and Vertical Line Removal

Post by fmw42 » 2010-03-17T10:28:24-07:00

Two reasons my technique above with -convolve does not work is 1) your lines are not perfectly vertical and MORE IMPORTANT 2) your lines are thicker than 1 pixel wide, which was the assumption of the convolution kernel provided above for my example.

Unfortunately, I am not sure what you can do to remove those lines.

You can try -lat and choose a filter size smaller than the thickness of the lines you want to remove, but larger than the text you want to preserve. My textcleaner will do that with the proper choice of filter size as it uses -lat. NOTE the larger the filter, the slower it will run.

But I would suggest you play with a smaller subsection of your image as your image is huge at 5000x6000 pixels.
Last edited by fmw42 on 2010-03-17T11:47:27-07:00, edited 2 times in total.

Evadido

Re: Horizontal and Vertical Line Removal

Post by Evadido » 2010-03-17T11:12:05-07:00

Ok, I'll try that, thanks a lot

abcdef
Posts: 9
Joined: 2014-08-16T23:28:43-07:00
Authentication code: 6789

Re: Horizontal and Vertical Line Removal

Post by abcdef » 2014-08-16T23:43:50-07:00

Can you please provide the matrix options to remove horizontal and vertical lines which are not clear. I could try matrix like 0,1,0 0,1,0 0,1,0 and found that some shades of the lines are removed.. but not significant. I tried 5x5 as well. Please suggest. The lines are more than 1pixel and width is not same at all places of the line.
Thanks
Vinod Bapatla

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

Re: Horizontal and Vertical Line Removal

Post by snibgo » 2014-08-17T04:52:25-07:00

You should start a new thread with your problem. Explain what you are trying to do. Provide a sample image (you can upload to somewhere like dropbox.com and paste the link here). Tell us what version of IM you are using, on what platform.
snibgo's IM pages: im.snibgo.com

vista123
Posts: 5
Joined: 2015-11-11T05:47:55-07:00
Authentication code: 1151

Re: Horizontal and Vertical Line Removal

Post by vista123 » 2017-10-03T07:01:28-07:00

Equivalent c# code?

User avatar
fmw42
Posts: 22232
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Horizontal and Vertical Line Removal

Post by fmw42 » 2017-10-03T15:21:27-07:00

vista123 wrote:
2017-10-03T07:01:28-07:00
Equivalent c# code?
Equivalent code to exactly what? Please always be specific. Provide your IM version and platform and an example of input and output and some command line.

Post Reply