I would like to use
import cv2
def adjust_gamma(image, gamma=1.0):
# build a lookup table mapping the pixel values [0, 255] to
# their adjusted gamma values
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
# apply gamma correction using the lookup table
return cv2.LUT(image, table)
to make invert gamma correction but my data is in [0,4095] format, so I adapt the code replacing 255 by 4095 and 256 by 4096:
import cv2
def adjust_gamma(image, gamma=1.0):
# build a lookup table mapping the pixel values [0, 255] to
# their adjusted gamma values
invGamma = 1.0 / gamma
table = np.array([((i / 4095.0) ** invGamma) * 4095
for i in np.arange(0, 4096)]).astype("uint8")
# apply gamma correction using the lookup table
return cv2.LUT(image, table)
But when trying to call the function on a random png image:
adjust_gamma(cv2.imread('myimage.png'), gamma=2.0)
I get the error:
OpenCV(3.4.3) /io/opencv/modules/core/src/lut.cpp:368: error: (-215:Assertion failed) (lutcn == cn || lutcn == 1) && _lut.total() == 256 && _lut.isContinuous() && (depth == CV_8U || depth == CV_8S) in function 'LUT'