I'm trying to develop a solution for emphasizing hand written text on a document. What I would like to get is an image where the document's background is white and the text is as visible as possible. Doesn't reaaly matter if it keeps its color or not. Here is what I did until now and the results I got:
def process_document_content(img):
flip_vertical = cv2.flip(img, -1)
f_height, f_width = img.shape[0], img.shape[1]
resized = cv2.resize(flip_vertical, None, fx=1050 / f_width, fy=735 / f_height,
interpolation=INTERPOLATION_METHOD)
gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
cv2.fastNlMeansDenoising(gray, gray, 3, 7, 21)
final = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 15, 2)
temp = cv2.pyrUp(final)
for i in range(0, 1):
temp = cv2.medianBlur(temp, 9)
temp1 = cv2.pyrDown(temp)
return temp1
This is the input image:
This is the result I got:
What I don't like about my result is that the text is a little too thick and in some places is discontinuous. I played with the parameter of the fastNlMeansDenoising and adaptiveThreshold functions to get a better result but to no end. Is there any better way to do this?

