Remove all horizontal and vertical lines from an image

后端 未结 2 1944
佛祖请我去吃肉
佛祖请我去吃肉 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.

提交回复
热议问题