2

I am trying to repair image contains letters each letter split into two halves from the middle.

original Image

enter image description here

After Applying the following code:

gray = cv2.cvtColor(cropped_bot, cv2.COLOR_BGR2GRAY)

new_img = ((gray >= 230)*255).astype('uint8')    

bottom_image =  255-new_img

I get this Image
enter image description here

My Problem is to fix the line that split the letters into two part.

I have tried adaptiveThreshold

cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 15, 2)

But it doesn't help. How I can solve this

ahmed osama
  • 621
  • 2
  • 12
  • 21
  • 1
    Possible duplicate of [How to identify incomplete rectangles in openCV](https://stackoverflow.com/questions/44295099/how-to-identify-incomplete-rectangles-in-opencv) – ivan_pozdeev Jun 15 '18 at 19:33

1 Answers1

3

Here are a few steps you can follow:

  • Perform Otsu threshold on the gray scale image
  • Apply morphological close operation with a kernel

Code :

ret, thresh1 = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
cv2.imshow('thresh1', thresh1)

enter image description here

k = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]], np.uint8)
closing = cv2.morphologyEx(thresh1, cv2.MORPH_CLOSE, k)
cv2.imshow(closing, closing)

enter image description here

UPDATE:

k1 = np.ones((3, 3), np.uint8)
erosion = cv2.erode(closing, k1, iterations = 1)
cv2.imshow(erosion, erosion)

enter image description here

Community
  • 1
  • 1
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87