This is my first post on Stack Overflow, so I am sorry if the problem isn't defined enough.
I am currently working on extracting table data from images and I need a way to dilate the text only in a vertical direction so that I can get clear column representation that will be used for further segmentation.
After removing horizontal and vertical lines and transforming the image bitwise, I am at this stage:
The ideal goal for this problem would be:
Is there a method or an algorithm that would be helpful in my case?
You can just call cv2.dilate
with the appropriate structuring element.
import cv2
pre_img = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)
h, w = pre_img.shape
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, ksize=(1, 2 * h))
dilated = cv2.dilate(pre_img, kernel)
cv2.imshow('input', pre_img)
cv2.imshow('output', dilated)
cv2.waitKey(0)
To visualize better what's happening:
blended = (pre_img.astype(float) + dilated.astype(float)) / 2
cv2.imshow('blended', blended.astype(np.uint8))
cv2.waitKey(0)