How do I increase the contrast of an image in Python OpenCV
<p>I am new to Python OpenCV. I have read some documents and answers <a href="http://stackoverflow.com/questions/19363293/whats-the-fastest-way-to-increase-color-image-contrast-with-opencv-in-python-c">here</a> but I am unable to figure out what the following code means:</p>

<pre><code>if (self.array_alpha is None):
    self.array_alpha = np.array([1.25])
    self.array_beta = np.array([-100.0])

# add a beta value to every pixel 
cv2.add(new_img, self.array_beta, new_img)                    

# multiply every pixel value by alpha
cv2.multiply(new_img, self.array_alpha, new_img)  
</code></pre>

<p>I have come to know that <code>Basically, every pixel can be transformed as X = aY + b where a and b are scalars.</code>. Basically, I have understood this. However, I did not understand the code and how to increase contrast with this.</p>

<p>Till now, I have managed to simply read the image using <code>img = cv2.imread('image.jpg',0)</code></p>

<p>Thanks for your help</p>

<p>Best explanation for <code>X = aY + b</code> (in fact it <code>f(x) = ax  + b</code>)) is provided at <a href="http://math.stackexchange.com/a/906280/357701">http://math.stackexchange.com/a/906280/357701</a> </p>

<p>A Simpler one by just adjusting lightness/luma/brightness for contrast as is below:</p>

<pre><code>import cv2

img = cv2.imread('test.jpg')
cv2.imshow('test', img)
cv2.waitKey(1000)
imghsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)


imghsv[:,:,2] = [[max(pixel - 25, 0) if pixel &lt; 190 else min(pixel + 25, 255) for pixel in row] for row in imghsv[:,:,2]]
cv2.imshow('contrast', cv2.cvtColor(imghsv, cv2.COLOR_HSV2BGR))
cv2.waitKey(1000)
raw_input()
</code></pre>

python opencv