mercredi 15 juin 2016

Python, OpenCV: Increasing image brightness without overflowing UINT8 array

I am trying to increase brightness of a grayscale image. cv2.imread() returns a numpy array. I am adding integer value to every element of the array. Theoretically, this would increase each of them. After that I would be able to put upper threshold of 255 and get the image with the higher brightness.

Here is the code:

grey = cv2.imread(path+file,0)

print type(grey)

print grey[0]

new = grey + value

print new[0]

res = np.hstack((grey, new))

cv2.imshow('image', res)
cv2.waitKey(0)
cv2.destroyAllWindows()

However, internal OpenCV routine apparently does something like that:

new_array = old_array % 255

Every pixel intensity value higher than 255 becomes a remainder of dividing by 255.

As a result, I am getting dark instead of completely white.

Here is the output:

<type 'numpy.ndarray'>
[115 114 121 ..., 170 169 167]
[215 214 221 ...,  14  13  11]

And here is the image:

enter image description here

How can I switch off this remainder mechanism? Is there any better way to increase brightness in OpenCV?

Aucun commentaire:

Enregistrer un commentaire