RGB to Lab Color Space Conversion: A Comprehensive Guide
To convert RGB color space to Lab color space, you need to use the following formulas:
-
Normalize RGB values: Divide each RGB value by 255 to obtain values in the range [0, 1].
-
Convert normalized RGB to linear RGB: Apply gamma correction to each normalized RGB value to get linear RGB values. The gamma correction formula is:
R' = R / 12.92 (R <= 0.04045) R' = ((R + 0.055) / 1.055) ^ 2.4 (R > 0.04045)
G' and B' are calculated similarly.
- Calculate XYZ values from linear RGB: Use the following matrix for conversion:
[0.4124 0.3576 0.1805] [0.2126 0.7152 0.0722] [0.0193 0.1192 0.9505]
where the first row represents the coefficients for X, the second row for Y, and the third row for Z. Matrix multiplication can be performed as follows:
[X Y Z] = [R' G' B'] * M
- Convert XYZ to Lab values: Use the following formulas:
Xn = 95.047 Yn = 100 Zn = 108.883
xn = X / Xn yn = Y / Yn zn = Z / Zn
f(t) = (t^(1/3)) (t > 0.008856) f(t) = 7.787 t + 16/116 (t <= 0.008856)
L* = 116 f(yn) - 16 a* = 500 (f(xn) - f(yn)) b* = 200 (f(yn) - f(zn))
The final result is L*, a*, b*.
原文地址: https://www.cveoy.top/t/topic/nYuK 著作权归作者所有。请勿转载和采集!