'Remove small dots from ocr data (python)

I want to remove little dots from my preprocessed ocr data. I work with opencv. That's what I have until now:

rectangle_img = img[y_min: y_max, x_min: x_max]
rectangle_img = cv2.cvtColor(rectangle_img, cv2.COLOR_RGB2GRAY)
rectangle_pil = PIL.Image.fromarray(rectangle_img)
rectangle_pil.show()

rectangle_img = cv2.adaptiveThreshold(rectangle_img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,15,2) #imgf contains Binary image
rectangle_pil = PIL.Image.fromarray(rectangle_img)
rectangle_pil.show()

rectangle_img = cv2.morphologyEx(rectangle_img, cv2.MORPH_CLOSE, (15, 15), iterations=1)
rectangle_pil = PIL.Image.fromarray(rectangle_img)
rectangle_pil.show()

the images:

enter image description here

Any ideas to improve my result?

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source