I have to recognize the text of the hand-filled bank form. The form has a grid as shown in the image. I am new to Image Processing. I read few papers on handwriting recognition and did denoising, binarization as preprocessing tasks. I want to segment the image now and recognize the characters using a Neural Network. To segment the characters I want to get rid of the grid.
Asked
Active
Viewed 3,968 times
4
-
SO is not a coding site. Please show some work so that we can help you with making it better. – DYZ Jan 24 '17 at 07:34
-
@DYZ I have tried using Denoising, Binarization and Edge detection on the image provided above. I am not understanding how to get rid of the grid. Any insights would be helpful. – Swapnil B. Jan 24 '17 at 07:38
-
try erosion and dilation operators – Micka Jan 24 '17 at 10:16
1 Answers
8
I have a solution using OpenCV.
First, I inverted the image:
ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
Now I performed morphological opening operation:
opening = cv2.morphologyEx(thresh2, cv2.MORPH_OPEN, k2)
cv2.imshow('opening', opening)
You can see that the grid lines have disappeared. But there are some gaos in some of the characters as well. So to fill the gaps I performed morphological dilation operation:
dilate = cv2.morphologyEx(opening, cv2.MORPH_DILATE, k1)
cv2.imshow('dilation', dilate)
You can check out THIS LINK for more morphological operations and kernels used.

Jeru Luke
- 20,118
- 13
- 80
- 87
-
@Soltius Hey any idea on how to get the characters back to normal as in the original image? – Jeru Luke Jan 24 '17 at 12:34
-
-
@Soltius **Closing** is generally used to fill some holes/speckles/gaps **inside** a binary image. [SEE HERE](http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html#morphological-ops) – Jeru Luke Jan 24 '17 at 12:40
-
Sure that's the general way it's used but I think it's useful here. It depends on the size and shape of kernel you use, but I tried it out with a (5,5) rectangular kernel (instead of the dilatation phase) and it closed some of the gaps :) – Soltius Jan 24 '17 at 12:53
-
@Soltius exactly!!! That is why I chose it. I tried out the different possibilities as well – Jeru Luke Jan 24 '17 at 12:57
-
@Jeru can we not take AND operation of the final image from your answer and my input image? That will give us the true characters with grid removed right? – Swapnil B. Jan 25 '17 at 07:11
-
@SwapnilB.AND operation of my final image with your inverse input image might work. Give it a try – Jeru Luke Jan 25 '17 at 07:21
-
-
-
@JeruLuke I want to see if you can help me do some stuff and I can pay you by the hours. If so, please send me an email to alexandergs@yahoo.com regards – alexandergs Apr 06 '18 at 17:34
-
@JeruLuke the kink to the kernels is broken, is it anywhere to be found? – Ezer K Sep 19 '21 at 19:00
-
@EzerK Check out [this link](https://opencv24-python-tutorials.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html) – Jeru Luke Sep 20 '21 at 11:32
-