Well tried morphology in Imagemagick, but unfortunately the output also affects the text, thus making it unsatisfactory for ocr. So is there any faster way to remove the lines from image without affecting the text for ocr?
Input image:
Imagemagick code:
magick 1sa.jpg -morphology close:1 "1x4: 0,1,1,0" result.png
Output image
Edit: Thanks to all those who replied. I finally made it work by the following code:
magick E:\1sa.jpg ( +clone -threshold 50% -negate -statistic median 219x1 ) -compose lighten -composite E:\z1.jpg
Your ImageMagick command is erroneous and should not even work. You need to make the kernel a horizontal line not vertical and you need a longer line for the kernel. Try the following:
magick 1sa.jpg -morphology bottomhat "20x1:0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0" -negate result.png
Adjust the kernel length as needed to optimize your result.
Is this ImageMagick command any better in the result?
convert 1sa.jpg -morphology bottomhat "20x3:0,0,0,0,0,0,0,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,1,1,1,1,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" -negate result.png