I have the following ImageMagick command that works very well for removing grid lines from a table image:
convert test.png -background white -deskew 40% -write mpr:img \
\( mpr:img -morphology close rectangle:30x1 -negate \) \
\( mpr:img -morphology close rectangle:1x30 -negate \) \
-evaluate-sequence add \
result.png
I can, of course, invoke this code from my Python script.
However, I would like to be able to translate this command into something pythonic like Wand, PIL, cv2 or whatever.
Namely for portability sake but also to avoid having to save the output.
Even though Wand, for instance, has a morphology function I do not seem to be able to figure out the kernel and so on.
As the real images contain confidential information, I have added a similar mock example. I have verified that the above command produces the desired results of entirely clearing the grid lines without affecting the quality of the text.
Here is a solution in Python/OpenCV.
Note I apply some (1 deg) rotation to your input for testing.
Input:
Threshold Image
Convex Hull Image:
Rotated Rectangle Image:
Deskewed Image:
Result Image: