Qix-/color-convert

Failure to convert XYZ to RGB and back #81

RobinBol posted onGitHub

Hi, first thanks for this great library!

I have an issue converting an XYZ value to RGB and back, it seems that for some values this works, but for others not. I could not find any range for the XYZ values in the readme (as for the other values), maybe it is related to that?.

This conversion matches (after rounding):

const startXYZ = [47.854955042890886, 29.320696241557958, 21.87902240817543]
const _rgb = convert.xyz.rgb(startXYZ);
const endXYZ = convert.rgb.xyz(_rgb) // => [ 48, 29, 22 ]

However, the following conversion is a mismatch (and quite some other value):

const startXYZ = [ 20, 87, 79 ]
const _rgb = convert.xyz.rgb(startXYZ);
const endXYZ = convert.rgb.xyz(_rgb) // => [ 48, 76, 75 ]

I have been fiddling with the color-space library as well, but that seems to have the same result (https://github.com/colorjs/color-space/issues/48). Is this a bug in the conversion algorithm?


XYZ and RGB do not have direct conversations; I'm not well versed in XYZ theory but if I recall correctly, it's an approximation and won't give you stable results when converting between the two.

posted by Qix- about 5 years ago

Closing as this conversion is lossy in nature (not all color models can be converted cleanly between one another).

posted by Qix- about 4 years ago

Fund this Issue

$0.00
Funded

Pull requests