Page 1 of 1

Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T03:26:37-07:00
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.

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T03:29:17-07:00
by mrjulio
I forgot to mention that I'm using ImageMagick-nox11-6.9.0.4,1 on unix.

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T04:46:48-07:00
by snibgo
What result do you expect? An all-black image?

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T06:20:39-07:00
by mrjulio
Yes, replace white with black. All lines are 1px thick.

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T07:29:56-07:00
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

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T07:53:51-07:00
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.

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T08:00:25-07:00
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.

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T08:08:30-07:00
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.

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T09:20:35-07:00
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

Re: Remove horizontal and vertical white lines on black background

Posted: 2015-04-23T13:13:39-07:00
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.