Ask Your Question

Getting the best threshold for each channel

asked 2018-12-04 09:13:08 -0500

Ahmed gravatar image

Hi, I'm trying to threshold an image for each channel, but I don't know the best method for determining the best threshold for an image, do you know any algorithms ?

import tesserocr
from PIL import Image
import pytesseract
import matplotlib.pyplot as plt
import cv2
import imutils
import numpy as np

image = cv2.imread(r'c:\ahmed\test2.png')

bin = np.all(np.array(image<131, dtype=np.uint8), axis=2)
inverted = cv2.bitwise_not( np.uint8(255*bin))

cv2.imshow("bin", inverted)

text = pytesseract.image_to_string(inverted, lang='ara')
with open(r"c:\ahmed\file.txt", "w", encoding="utf-8") as myfile:
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-12-05 22:29:32 -0500

Hi, Please try Adaptive Thresholding.

cv.ADAPTIVE_THRESH_MEAN_C : threshold value is the mean of neighborhood area. cv.ADAPTIVE_THRESH_GAUSSIAN_C : threshold value is the weighted sum of neighborhood values where weights are a gaussian window.

Here is url:

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-12-04 09:13:08 -0500

Seen: 17 times

Last updated: Dec 04