如何将实验室颜色空间更改为RGB 0255

2024-09-27 00:17:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有实验室数据集:val_Lab_2,如下所示:

[[ 7.803e+01  3.100e-01  1.382e+01]
 [ 6.697e+01 -7.400e+00  2.750e+01]
 [ 5.631e+01 -1.804e+01  1.599e+01]
 [ 6.701e+01  2.650e+00  2.913e+01]
 [ 6.564e+01  1.660e+00  2.540e+01]
 [ 3.537e+01  2.050e+01  3.784e+01]
 [ 4.178e+01  2.251e+01  4.438e+01]
 [ 6.129e+01  1.261e+01  5.934e+01]
 [ 4.269e+01  5.120e+00  4.995e+01]...]

我想将其更改为RGB 0-255,因此我使用colormath软件包:

import numpy as np
import pandas as pd 

from colormath.color_objects import sRGBColor, XYZColor, LabColor
from colormath.color_conversions import convert_color

val_rgb_2 = []
for lab_list in val_lab_2:
       lab = LabColor(*[component for component in lab_list])
       rgb = convert_color(lab, sRGBColor)
       rgb_list = [255*color for color in rgb.get_value_tuple()]
       val_rgb_2.append(rgb_list)
val_rgb_2 = np.array(val_rgb_2)
print(val_rgb_2)

结果表明:

[[201.44003158 192.14717152 167.2643737 ]
 [163.51015463 166.15931613 112.52909259]
 [109.8451797  143.64817993 106.17872676]
 [181.45664244 160.44644464 110.27374654]
 [174.70091435 157.51328159 113.65978481]
 [122.18753543  69.26114552  19.79086107]
 [143.2650315   82.85139354  20.50673141]
 [187.60706038 138.48640317  31.06087929]...]

然而,我认为这是不正确的,因为我有一个标签,前几行显示它应该是:

天然白色100%羊毛,蓝紫色花朵,蓝色花朵,花朵,全植物,果皮,果皮,果皮


Tags: infromimportforasnplabval
1条回答
网友
1楼 · 发布于 2024-09-27 00:17:58

我建议您使用此website来:

  • 插入LAB
  • 检查网站提供给您的RGB
  • 检查与插入的LAB/RGB关联的颜色

我已经做了检查,您编写的两个矩阵之间的转换是正确的。
例如,让我们尝试上面列表的第二个元素,它应该标记为蓝紫色的花

[ 6.697e+01 -7.400e+00  2.750e+01]

enter image description here

转换是正确的;我对标签有一些疑问

相关问题 更多 >

    热门问题