I have an input signature for which I want to remove the gridlines of same color.
So far I am using this python code to do that
import cv2
import numpy as np
## Load image and make B&W version
image = cv2.imread('Downloads/image.png')
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
# Remove horizontal
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (50,1))
detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
cnts = cv2.findContours(detected_lines, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
cv2.drawContours(thresh, [c], -1, (0,0,0), 2)
cv2.imwrite('Downloads/out.png', thresh)
Which takes me to the following image.
Now I am trying to infill the gaps introduced, I tried using a vertical kernel and morph close but that infills the other spaces in images a lot.
Any ideas on how I can achieve the said infilling using a more sophisticated operation and get the infill done without tampering with the existing signature much.