【问题标题】:Converting from RGB to LAB Colorspace - any insight into the range of L*A*B* values?从 RGB 转换为 LAB 色彩空间 - 了解 L*A*B* 值的范围吗?
【发布时间】:2014-02-08 05:37:31
【问题描述】:

在 OpenCV (Python) 中将图像从 RGB 转换为 LAB 时,我无法找到有关 L*A*B* 值范围的文档。寻找一些确认我的见解是正确的,因为这些数字相当奇特。我的亮度结果是 0-255,但对于 a 和 b,我分别得到 42-226 和 20-223。我知道这些值不需要有预先确定的范围,但是任何人都可以深入了解为什么选择这些范围吗?

为了它的价值,我尝试在 LAB 空间中创建颜色直方图,并且需要知道值的范围,以便以节省空间的方式存储 bin 值。

import cv2
import numpy as np
import sys
import urllib

print cv2.__version__ # 2.4.7
print sys.version # 2.7.5+ (default, Sep 19 2013, 13:48:49) \n[GCC 4.8.1]

# Load an image that contains all possible colors.
request = urllib.urlopen('http://www.brucelindbloom.com/downloads/RGB16Million.png')
image_array = np.asarray(bytearray(request.read()), dtype=np.uint8)
image = cv2.imdecode(image_array, cv2.CV_LOAD_IMAGE_COLOR)

# I was uncertain if it was BGR or RGB but in this case it doesn't matter because
# of my input image.
lab_image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
l_channel,a_channel,b_channel = cv2.split(lab_image)

# Print the minimum and maximum of lightness.
print np.min(l_channel) # 0
print np.max(l_channel) # 255

# Print the minimum and maximum of a.
print np.min(a_channel) # 42
print np.max(a_channel) # 226

# Print the minimum and maximum of b.
print np.min(b_channel) # 20
print np.max(b_channel) # 223

谢谢!

【问题讨论】:

  • 谷歌快速搜索提供了一个在线转换器,提供源代码:colormine.org/convert/rgb-to-lab
  • 感谢 M4rtini 的链接。我以前看过它,但它与我的问题无关。我正在寻找关于为什么 OpenCV 中的范围编号如此奇怪的见解。 colormine 计算的范围允许 a 和 b 的正值和负值,这在 OpenCV (Python) 中不是这种情况。无论如何,谢谢!

标签: python opencv color-space lab-color-space


【解决方案1】:

查看 OpenCV documentation(向下滚动到定义 RGB ↔ CIE L*a*b* 转换的位置),我们可以看到值重新调整到 0-255 范围:

L ← L * 255/100 ; a ← a + 128 ; b ← b + 128

此外:LAB 色彩空间涵盖了整个可感知的颜色光谱,而 RGB 则没有。因此,从 RGB 转换时,您不会看到整个值范围。

【讨论】:

  • 非常感谢,这正是我想要的。
【解决方案2】:

实际上a*b* 没有明确的限制,-127 to 127 只是为了轻松适应 8 位 Lab* 编码的约定...

根据 CIE 规范,L* 可以在 0 and 116 之间变化,但 Photoshop 和其他人停止在 100

通常可以在-127 and 127 之间定义值的原因是它通常适合gamut of real colors,请参阅Google 上的"gamut real colors Pointer"

【讨论】:

  • 你知道如何复制 Photoshop 的 LAB 模式吗?谢谢。
  • @Royi 嗨,这是一个非常棘手的问题,你能发个新帖子吗?我的回答太长了,无法发表评论,也给我链接...
  • 嗨,我发了,这里是:stackoverflow.com/questions/42558443/…
猜你喜欢
  • 2020-03-16
  • 2012-01-13
  • 1970-01-01
  • 2014-11-28
  • 1970-01-01
  • 2019-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多