如何在python的CIE L * a * b *图像中调整颜色曲线?

时间:2019-07-19 15:40:56

标签: python numpy image-processing cielab

在Photoshop中,可以在CIE L a b *颜色空间中调整L,a和b的颜色曲线。我正在尝试在python中使用伽玛校正执行类似的图像增强过程。

但是,这仅在一个方向上向左上方或右下方调整曲线。我可以在python中执行任何转换来调整曲线吗?

我已经应用了伽玛校正技术,但是这使颜色过于偏斜的一种方法。

我已经尝试了以下代码进行伽玛校正

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

0 个答案:

没有答案