Remove horizontal and vertical white lines on black background

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
mrjulio
Posts: 6
Joined: 2015-04-23T03:13:51-07:00
Authentication code: 6789

Remove horizontal and vertical white lines on black background

Post by mrjulio »

Hello guys,

This is my first post.
I need to remove H and V white lines with black background. The result is a grid generated using -canny 0x1+10%+25%.

The main problem is that the grid is slightly leaning: Image

I have tried with:

Code: Select all

convert source.jpg -morphology Thinning "1x14: 1,1,1,1,1,1,1,1,1,1,1,1,1,1" -morphology Thinning "14x3: 0,0,0,0,0,0,0,0,0,0,0,0,0,0 1,1,1,1,1,1,1,1,1,1,1,1,1,1 0,0,0,0,0,0,0,0,0,0,0,0,0,0" destination.jpg
... but i get a lot of islands afterwards.

Thank you.
mrjulio
Posts: 6
Joined: 2015-04-23T03:13:51-07:00
Authentication code: 6789

Re: Remove horizontal and vertical white lines on black background

Post by mrjulio »

I forgot to mention that I'm using ImageMagick-nox11-6.9.0.4,1 on unix.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove horizontal and vertical white lines on black background

Post by snibgo »

What result do you expect? An all-black image?
snibgo's IM pages: im.snibgo.com
mrjulio
Posts: 6
Joined: 2015-04-23T03:13:51-07:00
Authentication code: 6789

Re: Remove horizontal and vertical white lines on black background

Post by mrjulio »

Yes, replace white with black. All lines are 1px thick.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove horizontal and vertical white lines on black background

Post by fmw42 »

try this -- change all colors within 20% of white to black

Code: Select all

convert 2131wjq.jpg -fill black -fuzz 20% -opaque white result.jpg
mrjulio
Posts: 6
Joined: 2015-04-23T03:13:51-07:00
Authentication code: 6789

Re: Remove horizontal and vertical white lines on black background

Post by mrjulio »

fmw42 wrote:try this -- change all colors within 20% of white to black

Code: Select all

convert 2131wjq.jpg -fill black -fuzz 20% -opaque white result.jpg
This will generate a black image. The source is black and white and all I want is to remove lines.
Inside that grid I have text which is also white (result of -canny). I don't want to alter too much of that.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove horizontal and vertical white lines on black background

Post by fmw42 »

I do not see any text. Please be more specific about your questions and examples. Please post a real example with your text.

But I do not think you can remove the lines and not the text if they are both the same or closely the same color (white).

If you have two images, one with lines and text and one with only lines, then you can subtract the lines image from the image with both lines and text to remove the lines.

Applying morphology will also change your text.
mrjulio
Posts: 6
Joined: 2015-04-23T03:13:51-07:00
Authentication code: 6789

Re: Remove horizontal and vertical white lines on black background

Post by mrjulio »

This is an example after running this command on source:

Code: Select all

convert source -sharpen 0x3 -colorspace Gray -canny 0x1+10%+25% -morphology Thinning "1x14: 1,1,1,1,1,1,1,1,1,1,1,1,1,1" -morphology Thinning "14x3: 0,0,0,0,0,0,0,0,0,0,0,0,0,0 1,1,1,1,1,1,1,1,1,1,1,1,1,1 0,0,0,0,0,0,0,0,0,0,0,0,0,0" destination.jpg
Image

If I'm running Thinning with at least 14px long it will not alter the text too much as it will still be readable BUT the image is left with too many ugly islands from straight lines.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove horizontal and vertical white lines on black background

Post by fmw42 »

Did you try rotating the image to get the lines more horizontal and vertical, then apply the thinning, then rotate back?

You can also filter out long or short or selected lines using -connected-components. See http://magick.imagemagick.org/script/co ... onents.php
mrjulio
Posts: 6
Joined: 2015-04-23T03:13:51-07:00
Authentication code: 6789

Re: Remove horizontal and vertical white lines on black background

Post by mrjulio »

I tried rotating the original image to get the lines straight but after -canny i get pretty much the same result.

I will have a look at connected-components.
Thank you.
Post Reply