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.
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.