【发布时间】:2020-08-06 15:53:05
【问题描述】:
以下使用 RGB 颜色 255,0,0 创建红色图像
import numpy as np
import matplotlib.pyplot as plt
import cv2
width = 5
height = 2
array = np.zeros([height, width, 3], dtype=np.uint8)
array[:,:] = [255, 0, 0] # make it red
print(array)
plt.imshow(array)
plt.show()
输出:
[[[255 0 0]
[255 0 0]
[255 0 0]
[255 0 0]
[255 0 0]]
[[255 0 0]
[255 0 0]
[255 0 0]
[255 0 0]
[255 0 0]]]
如果我将数组转换为 LAB 空间:
array = cv2.cvtColor(array, cv2.COLOR_BGR2LAB)
print(array)
结果如下所示:
[[[ 82 207 20]
[ 82 207 20]
[ 82 207 20]
[ 82 207 20]
[ 82 207 20]]
[[ 82 207 20]
[ 82 207 20]
[ 82 207 20]
[ 82 207 20]
[ 82 207 20]]]
根据http://colorizer.org/,红色的值应该是:
lab(53.23, 80.11, 67.22)
为什么 opencv 会产生不同的值?我错过了什么吗?有没有可以查找的网站,例如,opebcv 的 Lab 颜色编号中的红色?谢谢。
PS:
一个问题是我使用了 COLOR_BGR2LAB 而不是 COLOR_RGB2LAB(感谢 Mark Setchell),但它仍然没有产生预期的 53.23、80.11、67.22 向量:54.4 83.2 78。这不接近但不一样。 ..
import numpy as np
import matplotlib.pyplot as plt
import cv2
width = 5
height = 2
array = np.zeros([height, width, 3], dtype=np.uint8)
array[:,:] = [255, 0, 0] # make it red
print(array)
array = cv2.cvtColor(array, cv2.COLOR_RGB2LAB)
array = array / 2.5
print(array)
【问题讨论】: