I would like to separate characters from borders after thresholding the images:
Original image
Touching areas
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