How do I increase the contrast of an image in Python OpenCV
Question: I am new to Python OpenCV. I have read some documents and answers
[here](http://stackoverflow.com/questions/19363293/whats-the-fastest-way-to-
increase-color-image-contrast-with-opencv-in-python-c) but I am unable to
figure out what the following code means:

    
    
    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)  
    

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

Till now, I have managed to simply read the image using `img =
cv2.imread('image.jpg',0)`

Thanks for your help


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

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

    
    
    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 < 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()
    

