3

I would like to separate characters from borders after thresholding the images:

Original image

Original Image

Touching areas

Touching areas

Desired Output

Desired Output

I'm using python and OpenCV to do the thresholding. Thanks in advance for your help.

This is part of the code that makes the threshold

def threshold_image(img):
   gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

   resized_img = cv2.resize(gray_img
    , None
    , fx=5.0
    , fy=5.0
    , interpolation=cv2.INTER_CUBIC)

    resized_img = cv2.GaussianBlur(resized_img,(5,5),0)#(5,5)

   equalized_img = cv2.equalizeHist(resized_img)
   # height of the image
   alto = int(resized_img.shape[0])  # shape[0] = rows
   # width of the image 
   ancho = int(resized_img.shape[1])  # shape[1] = cols

   reduced = cv2.cvtColor(reduce_colors(cv2.cvtColor(equalized_img, cv2.COLOR_GRAY2BGR), 6), cv2.COLOR_BGR2GRAY)

   ret, mask = cv2.threshold(reduced, 110, 255, cv2.THRESH_BINARY)#64
   cv2.imwrite('licence_plate_mask.png', mask)

   return mask 
KEVINPERCY
  • 31
  • 5
  • I'm voting to close this question as off-topic because it contains links to multiple off-site locations necessary to answer the question. – BlackVegetable Oct 02 '18 at 16:11
  • I don't see any external links? Those are stack-hosted images that they did not know how to embed for some reason, but your question is vague because you have not provided an attempt. Please post any relevant Python code that you have written to assist everyone. – Mr. Polywhirl Oct 02 '18 at 16:16
  • I added the code that makes the thresholding to the image, the result of this code is the "Original Image" which I want to process to obtain the last one. – KEVINPERCY Oct 02 '18 at 16:44
  • I'd suggest trying [scipy](https://docs.scipy.org/doc/scipy/reference/ndimage.html) for a better approach on making a suitable structuring element for morphing the image – Rick M. Oct 03 '18 at 07:50

1 Answers1

0

You can apply an erosion operation to your mask to disconnect the selected area.

You should be careful to not disconnect the "H" when eroding, you could change your kernel to affect the shape vertically the most.

You can read more about math morphology operators here.

JoOkuma
  • 462
  • 1
  • 4
  • 11