【发布时间】:2018-02-26 00:15:39
【问题描述】:
我的任务是将 RGB 图像转换为 LuvImage。 在该域中执行线性拉伸。然后将其转换回 RGB 域。
原图:
[[ 0 0 0]
[255 0 0]
[100 100 100]
[0 100 100]]
Luv域中线性拉伸后的Luv图像
[[0 , 0, 0],
[100 , 175, 37.7],
[79.64, 0, 0],
[71.2 ,-29.29,-6.339]]
现在,我将其转换为 XYZ 图像。答案是,
[[0,0, 0],
[1.5, 1, 0.53],
[0.533, 0.56, 0.61],
[0.344, 0.425, 0.523]]
现在,我将其转换为线性 sRGB 图像 通过将图像与矩阵相乘:
[[3.240479, -1.53715, -0.498535],
[-0.969256, 1.875991, 0.041556],
[0.055648, -0.204043, 1.057311]]
这种转换的答案 - 线性 sRGB 图像,
[[0. 0. 0. ],
[3.07132001 0.44046801 0.44082034],
[0.55904669 0.55972465 0.55993322],
[0.20106868 0.4850426 0.48520307]]
这里的问题是第二个像素的 sRGB 值不在 [0,1] 的范围内。对于所有其他像素,我得到了正确的值。
def XYZToLinearRGB(self, XYZImage):
'''
to find linearsRGBImage, we multiply XYZImage with static array
[[3.240479, -1.53715, -0.498535],
[-0.969256, 1.875991, 0.041556],
[0.055648, -0.204043, 1.057311]]
'''
rows, cols, bands = XYZImage.shape # bands == 3
linearsRGBImage = np.zeros([rows, cols, bands], dtype=float)
multiplierMatrix = np.array([[3.240479, -1.53715, -0.498535],
[-0.969256, 1.875991, 0.041556],
[0.055648, -0.204043, 1.057311]])
for i in range(0, rows):
for j in range(0, cols):
X,Y,Z = XYZImage[i,j]
linearsRGBImage[i,j] = np.matmul(multiplierMatrix, np.array([X,Y,Z]))
#for j -ends
#for i -ends
return linearsRGBImage
此转换的代码如上。有人可以指出我在第二个像素上做错了什么,以及如何解决它?
【问题讨论】:
-
您确定映射将始终在包含的空间内吗?有时颜色空间能够表达其他颜色空间无法表达的颜色。
-
是的,对于 XYZ 范围未定义。但是对于线性 sRGB,它应该在 [0,1] 之内。对于 Luv,L 应在 [0,100] 范围内。
标签: python-3.x computer-vision srgb color-conversion cieluv