Ask Your Question

Revision history [back]

How to increase contrast of a image with text

I have an image that contains text. Before sending it to OCR, I would like to increase the contrast of it.

The original image is like this:

image description

I can increase the contrast of the text using imagemagick: convert orig.jpg -level 60%x85% contrast.jpg. This turns the image into

image description

The imagemagick code is basically doing this http://www.imagemagick.org/script/command-line-options.php?#level

In normal usage (-level) the image values are stretched so that the given 'black_point' value in the original image is set to zero (or black), while the given 'white_point' value is set to QuantumRange (or white). This provides you with direct contrast adjustments to the image. The 'gamma' of the resulting image will then be adjusted.

Question

How can I do the same thing in OpenCV? I tried the adjust_gamma function mentioned in the PyImageSeach blog post http://www.pyimagesearch.com/2015/10/05/opencv-gamma-correction/ but it didn't help my case.

How to increase contrast of a image with text

I have an image that contains text. Before sending it to OCR, I would like to increase the contrast of it.

The original image is like this:

image description

I can increase the contrast of the text using imagemagick: convert orig.jpg -level 60%x85% contrast.jpg. This turns the image into

image description

The imagemagick code is basically doing this http://www.imagemagick.org/script/command-line-options.php?#level

In normal usage (-level) the image values are stretched so that the given 'black_point' value in the original image is set to zero (or black), while the given 'white_point' value is set to QuantumRange (or white). This provides you with direct contrast adjustments to the image. The 'gamma' of the resulting image will then be adjusted.

Question

How can I do the same thing in OpenCV? I tried the threshold functions with adjust_gammacv2.THRESH_BINARY function mentioned in the PyImageSeach blog post http://www.pyimagesearch.com/2015/10/05/opencv-gamma-correction/ but it didn't help my case.doesn't produce the same result.