0

I'm using

import cv2
cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, 
                                    cv2.THRESH_BINARY_INV,
                                    11,
                                    0)

in python to compute a preprocess on different types of images. Since a constant C (0 in this case) and the kernel size (11 in this case) can be good for a specific type of image and bad for another type, is there a way to calculate them dynamically using some features of an image?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Will
  • 1,619
  • 5
  • 23
  • The block size depends on the size of the features that you want to isolate. This raises two difficulties: 1) no algorithm can guess which features you are after, 2) finding the size of the features present requires segmentation methods harder than adaptive thresholding. –  Apr 04 '22 at 14:07
  • Just one thing is granted: a constant value 0 is usually a very poor choice. –  Apr 04 '22 at 14:09
  • To the best of my knowledge, what you can do for a specific case is to collect a representative sample of images, adjust the constants by hand for each, and keep the values that work best. Also question the "why" you need adaptive thresholding. –  Apr 04 '22 at 14:12
  • @YvesDaoust I tried with Otsu, but for some images I lost some parte of the text – Will Apr 04 '22 at 14:14
  • Is the character size fixed ? –  Apr 04 '22 at 14:23
  • no, depends on the image type – Will Apr 04 '22 at 14:28
  • @YvesDaoust also, is better to use cv2.THRESH_BINARY_INV or cv2.THRESH_BINARY ? for pytesseract? – Will Apr 04 '22 at 14:28
  • There is no universal solution. –  Apr 04 '22 at 14:35

0 Answers0