# Revision history [back]

### How to get the optimal binary threshold value

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:

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

...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:

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

...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

### How to get the optimal binary threshold value

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:

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

...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:

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

...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

 3 retagged sturkmen 6452 ●3 ●43 ●74 https://github.com/stu...

### How to get the optimal binary threshold value

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:

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

...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:

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

...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