从RGB到LAB颜色空间的转换 - 有关L*A*B*值范围的任何见解?

17

我无法在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

谢谢!


快速的谷歌搜索提供了一个在线转换器,附带源代码:http://colormine.org/convert/rgb-to-lab - M4rtini
1
感谢你的链接M4rtini。我之前看过它,但它与我的问题无关。我正在寻找有关为什么OpenCV中的范围数字如此奇怪的见解。由colormine计算的范围允许a和b的正负值,但在OpenCV(Python)中并非如此。不管怎样,还是谢谢! - Daniel Castro
2个回答

26

查看OpenCV的文档(向下滚动到定义RGB ↔ CIE L*a*b*转换的位置),我们可以看到其值被重新缩放为0-255范围:

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

此外:LAB颜色空间涵盖了可感知颜色的整个光谱,而RGB则不是。因此,从RGB进行转换时你将无法看到整个值范围。


1
实际上,a*b*没有明确定义的限制,-127至127只是为了方便适配8位Lab*编码而约定的...
按照CIE规范,L*可以在0到116之间变化,但Photoshop等软件停留在100
通常定义-127至127之间的值是因为它通常适配于真实颜色的色域,请参阅Google上的"gamut real colors Pointer"

你知道如何复制 Photoshop 中的 LAB 模式吗?谢谢。 - Royi
@Royi 你好,这是一个非常棘手的问题,你能不能发布一个新帖子?我的答案太长了,无法在评论中回复。请给我链接... - adrienlucca.net
嗨,我发布了,这是链接:https://dev59.com/15_ha4cB1Zd3GeqP2KQ0 - Royi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接