I have built a code for Image Binarization and it works kind of well but the texts in my binary images either get too big or there's some white noise in them. What I want to do it to try Erosion, Dilation, Opening, Closing individually and then see which one is improving the results for me. Where should I use these morphological operations in my code. For example In Between Sharpened and binary image or between division and sharpened?
import numpy as np
import cv2
import skimage.filters as filters
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
smooth = cv2.GaussianBlur(gray, (93,93), 0,)
division = cv2.divide(gray, smooth, scale=255)
# kernel = np.ones((5,5),np.uint8) # use operations here
# opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
sharp = filters.unsharp_mask(division, radius=1.5, amount=1.5, multichannel=False, preserve_range=False)
sharp = (255*sharp).clip(0,255).astype(np.uint8)
# kernel = np.ones((5,5),np.uint8) # or here
# opening = cv2.morphologyEx(sharp, cv2.MORPH_OPEN, kernel)
thresh = cv2.threshold(sharp, 0, 255, cv2.THRESH_OTSU )[1]