Ask Your Question
0

Getting the best threshold for each channel

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

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')
print(text)
with open(r"c:\ahmed\file.txt", "w", encoding="utf-8") as myfile:
    myfile.write(text)
cv2.waitKey(0)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

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

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: https://docs.opencv.org/3.4/d7/d4d/tu...

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 376 times

Last updated: Dec 04 '18