我正在尝试将 RGB 转换为 Lab,然后将 a 和 b 通道归零以获得灰度图像,但我得到的图像带有红橙色调

I am trying to convert RGB to Lab and then zero the a and b channels to get a grayscale image but I get an image with reddish orange tint

我的代码:

imgrey = np.asarray(ibuffer).copy()
grey = cv2.cvtColor(imgrey, cv2.COLOR_BGR2Lab)
grey[:,:,1] = 0
grey[:,:,2] = 0
grey = cv2.cvtColor(grey,cv2.COLOR_LAB2BGR)
photo = Image.fromarray(grey)
photo = resize(photo)
photo = ImageTk.PhotoImage(photo)
canvas.photo = photo
canvas.create_image(0,0,anchor="nw",image = photo)

我想使用它的 Lab 值来处理我的图像,但是当处理过的 Lab 值被转换回 RGB 时,这样做会产生错误的输出。

Orginal Picture

Output Picture

如果你只想要一张灰度图像,OpenCV 有 cvtColor(img, cv2.COLOR_BGR2GRAY) 这将 return 单通道灰度图像。你也可以只使用LAB图像的L通道,它看起来像一个灰度图像(但我认为它不完全一样)。

修改实验室图像的 'a' 和 'b' 通道可能有点不直观,因为每个通道使用 'positive' 和 'negative' 控制不同的颜色饱和度价值。这是一个从 128 开始朝两个方向移动的滑动刻度。这就是为什么将它们设置为零不是灰色,它实际上是在一个方向上完全饱和。我怀疑如果你将它们都设置为 128 你会得到你想要的。