pythonopencvhandwriting

Removing grid from scanned image


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.

Thank you very much in advance. enter image description here


Solution

  • I have a solution using OpenCV.

    First, I inverted the image:

    ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
    

    enter image description here

    Now I performed morphological opening operation:

    opening = cv2.morphologyEx(thresh2, cv2.MORPH_OPEN, k2)
    cv2.imshow('opening', opening) 
    

    enter image description here

    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) 
    

    enter image description here

    You can check out THIS LINK for more morphological operations and kernels used.