Remove all horizontal and vertical lines from an image

后端 未结 2 1945
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 07:55

I want to remove all horizontal and vertical lines but some small vertical lines are not getting removed. Adding the input and output images and the code below.



        
相关标签:
2条回答
  • 2021-01-01 08:14

    In Imagemagick, you can use morphology close, but the result must be combined back with the original to remove the lines. The morphology close makes short horizontal or vertical segments white and leaves the long black lines. So the result must be negated and added to the original. It is important to make the morphology lines smaller than the shortest line segment, but longer than any parts of the text. So below, I process the image for the vertical lines and negate. Then repeat for the horizontal lines white and negate. Then I combine the two sets of lines and add them together. Finally I add the combined lines to the original image.

    Input:

    Imagemagick 6, Unix Syntax:

    convert \( image.png -alpha off \) \
    \( -clone 0 -morphology close rectangle:1x50 -negate +write tmp1.png \) \
    \( -clone 0 -morphology close rectangle:50x1 -negate +write tmp2.png \) \
    \( -clone 1 -clone 2 -evaluate-sequence add +write tmp3.png \) \
    -delete 1,2 \
    -compose plus -composite \
    result.png
    


    Imagemagick 6 Windows Syntax:

    convert ( image.png -alpha off ) ^
    ( -clone 0 -morphology close rectangle:1x50 -negate +write tmp1.png ) ^
    ( -clone 0 -morphology close rectangle:50x1 -negate +write tmp2.png ) ^
    ( -clone 1 -clone 2 -evaluate-sequence add +write tmp3.png ) ^
    -delete 1,2 ^
    -compose plus -composite ^
    result.png
    


    tmp1 (vertical lines):

    tmp2 (horizontal lines):

    tmp3 (combined and negated lines):

    Result:

    For Imagemagick 7, change convert to magick.

    You should be able to do this in Windows Imagemagick with Magick.NET. See https://github.com/dlemstra/Magick.NET. But I suspect your emgu.cv tool has the same morphology tools.

    0 讨论(0)
  • 2021-01-01 08:39

    You can do this with ImageMagick library easily, just use some predefined filter

    I am not sure this works with tiff format , you may need convert your tiff file to bmp/png/jpb first

    This removes horizontal lines

     convert rtaImage.png -morphology close:1 "1x5: 0,1,1,1,0"
    

    this removes both

     convert rtaImage.png -convolve "0,$v,0,0,$v,0,0,$v,0" -threshold 99% rtaImage2.png
    
    0 讨论(0)
提交回复
热议问题