How to get the optimal binary threshold value

asked 2018-08-07 05:45:22 -0600

JimQ gravatar image

updated 2020-10-05 12:53:24 -0600

Hi, I'm trying to use opencv to process text images before sending them to OCR. This involves binarizing the images, but because they vary greatly (from very dark to very faint), I need an adaptive thresholding method. I tried Otsu but id doesn't give the desired result. This is my original image: Original

...and this is what its like after Otsu thresholding: Otsu

...Otsu calculates a threshold of 238 for this image, but if I experiment manually, I find that that a threshold of 222 produces a better result as follows: Threshold 222

If I try adaptiveThreshold, the best I get is (with a block size of 17 and a C of 6) as follows: image description

...but this is still not as good as the 222 image. Can anyone suggest a programmatic way of coming up with an optimal threshold value? ....or some other adaptive method which might give me better results?

Any help would be much appreciated Thanks Jim

edit retag flag offensive close merge delete

Comments

Image histogram is not really bimodal : I don't think there is good method to find 222

LBerger gravatar imageLBerger ( 2018-08-07 08:20:37 -0600 )edit