I performed image preprocessing to obtain a good image for text extraction, but after applying the adaptiveThreshold process, I found that the characters were incomplete. For example, some pixels were too large, some were too small, and some were missing, resulting in characters that were incomplete and unclear.
And this is my code before the issue occurred.
import cv2
import numpy as np
imRGB = cv2.imread('D:\Senior-project\images\024.jpg')
print(imRGB.shape)
imGray = cv2.cvtColor(imRGB, cv2.COLOR_BGR2GRAY)
print(imGray.shape)
blur = cv2.GaussianBlur(imGray, (3,3), 0)
cv2.imwrite('blur.jpg', blur)
contrast = cv2.convertScaleAbs(blur, alpha=1.5, beta=0)
cv2.imwrite('contrast.jpg', contrast)
thresh = cv2.adaptiveThreshold(contrast, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 7)
cv2.imwrite('thresh.jpg', thresh)
My original image
thresh.jpg
The image showing the character issues I mentioned
I tried to solve the issue by using Morphological operations.
kernel = np.array([[0,1,0], [1,1,1], [0,1,0]], np.uint8)
img_erosion = cv2.erode(thresh, kernel, iterations=1)
cv2.imwrite('img_erosion.jpg', img_erosion)
img_dilation = cv2.dilate(img_erosion, kernel, iterations=1)
cv2.imwrite('img_dilation.jpg', img_dilation)
However, it seems that using the Erosion operation causes the characters to become too enlarged, leading to incomplete and unclear characters in the image. Similarly, when applying the Dilation operation after Erosion to erode and reduce the size of objects, the result only made the characters even more incomplete.
img_erosion.jpg
img_dilation.jpg
Are there any ways to restore the characters in an image to be complete and clear after using adaptiveThreshold? I’ve tried various solutions, including Morphological operations and using Filter2D(), but I still haven’t been able to resolve the issue.