I have two sets of values RGB and XYZ in np.arrays that have the same length. The values in RGB and XYZ correspond to the same values in two different color spaces, the order of their appearance in the vectors is the same.
I have another array RGB_picture that contains values similar to the ones listed in RGB.
I want to find a way to replace the RGB values in RGB_picture by the corresponding XYZ values in a new array XYZ_picture.
example:
RGB = np.array([[0,0,0], [0,0,1], [0,1,0], [0,1,1], [1,0,0], [1,0,1], [1,1,1]])
XYZ = np.array([[0.237,0.32,0.8642], [0.43234,0.34,1], [0.2432,.31,0.324], [0.3242,1.324,1.234], [1.32,0.4,0.23], [1.432,0.32423,1.342], [1.234,1.324,1.324324]])
#6 pixels image
RGB_image = np.array([[[0,0,1],[0,0,1],[0,0,1],
[0,1,1],[1,0,0],[1,0,1]]])
"""I want to return this"""
>print XYZ_image
>[[0.43234,0.34,1],[0.43234,0.34,1],[0.43234,0.34,1]],
>[0.3242,1.324,1.234], [1.32,0.4,0.23], [1.432,0.32423,1.342]]
I tried to do it with numpy but couldn't find how, would you help a bit?
Here's what I have but it is no numpy solution, so it is very slow:
XYZ_image = np.zeros_like(RGB_image)
w, h = RGB_image.shape
for i in xrange(w):
for j in xrange(h):
pixel = RGB_image[i,j]
for k in xrange(len(RGB)):
rgb = RGB[k]
if rgb == pixel:
XYZ_image[i,j] = XYZ[k]
break