In Photoshop, it is possible to adjust the color curves of L,a,and b in the CIE Lab* color space. I am attempting to perform a similar process for image enhancement using gamma correction in python.
However, this only adjusts the curve in one direction, either towards the top left or bottom right. Is there any transformation I can perform in python to adjust the curves?
I have applied gamma correction techniques but that skews the color too much one way.
I have tried the below code for gamma correction
def adjust_gamma(image, gamma=1.0):
m,n,c = image.shape
res = np.zeros((m,n,c))
# 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,res)
def toLAB(image, input_type = 'BGR'):
conversion = cv2.COLOR_BGR2LAB if input_type == 'BGR' else cv2.COLOR_RGB2LAB
image_LAB = cv2.cvtColor(image, conversion)
y,x,z = image_LAB.shape
LAB_flat = np.reshape(image_LAB, [y*x,z])
colors = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) if input_type == 'BGR' else image
colors = np.reshape(colors, [y*x,z])/255.
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xs=LAB_flat[:,2], ys=LAB_flat[:,1], zs=LAB_flat[:,0], s=10, c=colors, lw=0)
ax.set_xlabel('A')
ax.set_ylabel('B')
ax.set_zlabel('L')
plt.show()
return image_LAB
lab_image = toLAB(image_BGR)
L,a,b = cv2.split(lab_image)
l = np.zeros((500,500,3))
l[:,:,0] = b
l[:,:,1] = b
l[:,:,2] = b
l = np.uint8(l)
adjusted = adjust_gamma(l, gamma=1.2)
cv2_imshow(np.hstack([l, adjusted]))
gamma_lab = cv2.merge([L,a,adjusted[:,:,0]])
# final_image = cv2.cvtColor(merged_channels, cv2.COLOR_LAB2BGR)
new = cv2.cvtColor(gamma_lab, cv2.COLOR_LAB2BGR)```