[Python] Are there any effective ways of image binarization that can deal with varying...

Discussão em 'Python' iniciado por Stack, Janeiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to perform OCR on an Arabic manuscript, but I'm facing difficulties with regards to binarizing the image (i.e. ensuring that regions of text are given intensity 0 and background regions are given intensity 255).

    Otsu's thresholding Adaptive thresholding

    Otsu's thresholding does not seem to be very effective in situations of varying brightness levels. I applied this algorithm to a sample image (see below) and there are several regions which don't have text, yet appear black. I also applied an adaptive thresholding algorithm and that binarizes the image slightly better but now there's a lot of noise throughout the image. The code I used is as follows:

    def binarized_image(image):

    # binarized_image = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 5, 2)
    threshold, binarized_image = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    return binarized_image


    I am aware that these are very simplistic methods. This is my first time doing such a large project so any help will be appreciated!

    Continue reading...

Compartilhe esta Página