Last active
May 22, 2021 16:29
-
-
Save behreajj/5fb5dc60fcfbb06f3e8cdb5f1a6580bf to your computer and use it in GitHub Desktop.
CIE XYZ CIE LAB Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector xyzToLab(vector xyz) { | |
float vx = xyz[0] / 0.95047; | |
float vy = xyz[1]; | |
float vz = xyz[2] / 1.08883; | |
vx = select(7.787 * vx + 16.0 / 116.0, pow(vx, 1.0 / 3.0), vx > 0.008856); | |
vy = select(7.787 * vy + 16.0 / 116.0, pow(vy, 1.0 / 3.0), vy > 0.008856); | |
vz = select(7.787 * vz + 16.0 / 116.0, pow(vz, 1.0 / 3.0), vz > 0.008856); | |
return vector( | |
116.0 * vy - 16.0, | |
500.0 * (vx - vy), | |
200.0 * (vy - vz)); | |
} | |
vector labToXyz(vector lab) { | |
float vy = (lab[0] + 16.0) / 116.0; | |
float vx = lab[1] / 500.0 + vy; | |
float vz = vy - lab[2] / 200.0; | |
float vye3 = vy * vy * vy; | |
float vxe3 = vx * vx * vx; | |
float vze3 = vz * vz * vz; | |
vy = select((vy - 16.0 / 116.0) / 7.787, vye3, vye3 > 0.008856); | |
vx = select((vx - 16.0 / 116.0) / 7.787, vxe3, vxe3 > 0.008856); | |
vz = select((vz - 16.0 / 116.0) / 7.787, vze3, vze3 > 0.008856); | |
return vector(vx * 0.95047, vy, vz * 1.08883); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment