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:
I can increase the contrast of the text using imagemagick: convert orig.jpg -level 60%x85% contrast.jpg
. This turns the image into
The imagemagick code is basically doing this http://www.imagemagick.org/script/com...
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 cv2.THRESH_BINARY
but it doesn't produce the same result.
use lut like in this post
I tried using LUT as mentioned in this post http://www.pyimagesearch.com/2015/10/... however, the results were not same as imagemagick at all
Of course you have to understand what is a lut : linear : lut[i]=i exponential lut[i]=exp(i)/(exp(256))*256 : dangerous lut
if you want to have same results than image magick save an image x in opencv with x[i,j]=i; apply your transform in image magick. Open result image in opencv and you have your specific LUT
Well I don't want to use imagemagick because that is not part of my automated pipeline. I would rather have the results replicated in opencv....maybe not exactly like imagemagick but close to it. I agree the LUT formula in the referenced blog post seems very aggressive. Instead, I am looking for something that makes the black pixels blacker and white pixels whiter.