Sunday, 5 September 2021

How to improve the binarization of Text document ( Fill missing pixels of alphabets, reduce noise etc)

What (and how) can be done (like where exactly to plcae Erosion, Dialiation, Opening, Closing etc) so that the words are not cut / invisible in between (maybe some other binarization technique which works on most of the cases or some parameter tuning)

I have this code to binarize / Threshold the image. It works fine on a wide range of images except a couple of things and the major problem being that it leads to loss of info due to some brightness and other factors. Some of the words are not readable or gets broken. Below is the code to threshold / Binarize along with some of the images. Also, here is the link to 200 sample and resulting images

import cv2
import skimage.filters as filters

def convert(path):
    img = cv2.imread(path)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    smooth = cv2.GaussianBlur(gray, (103,103), 0)

    division = cv2.divide(gray, smooth, scale=255)

    sharp = filters.unsharp_mask(division, radius=1.5, amount=5, multichannel=False, preserve_range=False) # High Radius increase the density or surrounding pixels making it dense
    sharp = (255*sharp).clip(0,255).astype(np.uint8)

    thresh = cv2.threshold(sharp, 0, 255, cv2.THRESH_OTSU )[1] 
    return thresh

enter image description here enter image description here



from How to improve the binarization of Text document ( Fill missing pixels of alphabets, reduce noise etc)

No comments:

Post a Comment