I need to segment touching characters from an image
I used skeletonization to get the outline of the image
Now I want to connect the vertical lines and in order to identify separating lines for characters
I tried using morphological operations but it is difficult to identify a kernel that works with different images. Can anyone suggest a better method to connect the marked lines and get the required region?
Here's my code
import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.morphology import skeletonize
from skimage.util import invert
from skimage.measure import label
org = cv2.imread('crop.png')
image = cv2.copyMakeBorder(org, top=3, bottom=3, left=3, right=3,
borderType=cv2.BORDER_CONSTANT,
value=[0, 0, 0])
img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
img = invert(img)
skele = skeletonize(img//255)
skele = (skele * 255).astype(np.uint8)
labels = label(skele)
assert(labels.max() != 0 )
largestCC = labels == np.argmax(np.bincount(labels.flat)[1:])+1
largestCC = (largestCC * 255).astype(np.uint8)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(1,8))
d_im = cv2.dilate(largestCC, kernel, iterations=1)
e_im = cv2.erode(d_im, kernel, iterations=1)
plt.imshow(largestCC)
plt.show()
plt.imshow(e_im)
plt.show()