|
I want to convert the RGB color space to LUV
How to do that
Many thanks!
Accepted Answer from ho_alan
Date: 12/30/2004 08:43AM PST
Grade: A
RGB -> CIE XYZitu (D65): |X| |0.430574 0.341550 0.178325| |Red | |Y| = |0.222015 0.706655 0.071330| * |Green| |Z| |0.020183 0.129553 0.939180| |Blue | This provides the formula to transform RGB to CIE XYZitu and vice-versa: RGB -> CIE XYZitu (D65) | CIE XYZitu (D65) -> RGB X = 0.431*Red+0.342*Green+0.178*Blue | Red = 3.063*X-1.393*Y-0.476*Z Y = 0.222*Red+0.707*Green+0.071*Blue | Green = -0.969*X+1.876*Y+0.042*Z Z = 0.020*Red+0.130*Green+0.939*Blue | Blue = 0.068*X-0.229*Y+1.069*Z CIE XYZ -> CIE Lab { L* = 116*((Y/Yn)^(1/3)) whether Y/Yn>0.008856 { L* = 903.3*Y/Yn whether Y/Yn<=0.008856 u* = 13*(L*)*(u'-u'n) v* = 13*(L*)*(v'-v'n) where u'=4*X/(X+15*Y*+3*Z) and v'=9*Y/(X+15*Y+3*Z) and u'n and v'n have the same definitions for u' and v' but applied to the white point reference. So, you have: u'n=4*Xn/(Xn+15*Yn*+3*Zn) and v'n=9*Yn/(Xn+15*Yn+3*Zn) | ||
Comment from ho_alan Date: 12/30/2004 08:44AM PST | Comment | |
hope it helps:-) | ||
Comment from grg99 Date: 12/30/2004 02:05PM PST | Comment | |
First I'd check whatever graphics package you are using to display your images. 97.795% of them have built-in functions for converting between the different color representations. Many of those are a lot faster than any code you coul dwrite, as they use video hardware assistance to convert a whole image in a flash. |
Silly questions
http://www1.tip.nl/~t876506/ColorDesign.html#sil
Why did you write color instead of colour?
Many more people looking for pages on the internet know the American spelling color better than the British spelling colour. But in the meta-tags of this document also a 'colour' keyword has been incorporated.
Transformavimo formules: http://www.easyrgb.com/math.html
Yxy —> XYZ
//Y = From 0 to 100
//x = From 0 to 1
//y = From 0 to 1
X = x * (Y / y)
Y = Y
Z = (1 - x - y) * (Y / y)
XYZ —> RGB
ref_X = 95.047 //Observer = 2°, Illuminant = D65
ref_Y = 100.000
ref_Z = 108.883
var_X = X / 100 //X = From 0 to ref_X
var_Y = Y / 100 //Y = From 0 to ref_Y
var_Z = Z / 100 //Z = From 0 to ref_Y
var_R = var_X * 3.2406 + var_Y * -1.5372 + var_Z * -0.4986
var_G = var_X * -0.9689 + var_Y * 1.8758 + var_Z * 0.0415
var_B = var_X * 0.0557 + var_Y * -0.2040 + var_Z * 1.0570
if (var_R > 0.0031308) var_R = 1.055 * (var_R ^ (1 / 2.4)) - 0.055
else var_R = 12.92 * var_R
if (var_G > 0.0031308) var_G = 1.055 * (var_G ^ (1 / 2.4)) - 0.055
else var_G = 12.92 * var_G
if (var_B > 0.0031308) var_B = 1.055 * (var_B ^ (1 / 2.4)) - 0.055
else var_B = 12.92 * var_B
R = var_R * 255
G = var_G * 255
B = var_B * 255
RGB —> XYZ
var_R = (R / 255) //R = From 0 to 255
var_G = (G / 255) //G = From 0 to 255
var_B = (B / 255) //B = From 0 to 255
if (var_R > 0.04045) var_R = ((var_R + 0.055) / 1.055) ^ 2.4
else var_R = var_R / 12.92
if (var_G > 0.04045) var_G = ((var_G + 0.055) / 1.055) ^ 2.4
else var_G = var_G / 12.92
if (var_B > 0.04045) var_B = ((var_B + 0.055) / 1.055) ^ 2.4
else var_B = var_B / 12.92
var_R = var_R * 100
var_G = var_G * 100
var_B = var_B * 100
//Observer. = 2°, Illuminant = D65
X = var_R * 0.4124 + var_G * 0.3576 + var_B * 0.1805
Y = var_R * 0.2126 + var_G * 0.7152 + var_B * 0.0722
Z = var_R * 0.0193 + var_G * 0.1192 + var_B * 0.9505
XYZ —> Yxy
//X = From 0 to 95.047 Observer. = 2°, Illuminant = D65
//Y = From 0 to 100.000
//Z = From 0 to 108.883
Y = Y
x = X / (X + Y + Z)
y = Y / (X + Y + Z)
Yxy —> XYZ
//Y = From 0 to 100
//x = From 0 to 1
//y = From 0 to 1
X = x * (Y / y)
Y = Y
Z = (1 - x - y) * (Y / y)
XYZ —> Hunter-Lab
H)L = 10 * sqrt(Y)
(H)a = 17.5 * (((1.02 * X) - Y) / sqrt(Y))
(H)b = 7 * ((Y - (0.847 * Z)) / sqrt(Y))
Hunter-Lab —> XYZ
var_Y = (H)L / 10
var_X = (H)a / 17.5 * (H)L / 10
var_Z = (H)b / 7 * (H)L / 10
Y = var_Y ^ 2
X = (var_X + out_Y) / 1.02
Z = -(var_Z - out_Y) / 0.847
XYZ —> CIE-L*ab
var_X = X / 95.047 //Observer = 2°, Illuminant = D65
var_Y = Y / 100.000
var_Z = Z / 108.883
if (var_X > 0.008856) var_X = var_X ^ (1/3)
else var_X = (7.787 * var_X) + (16 / 116)
if (var_Y > 0.008856) var_Y = var_Y ^ (1/3)
else var_Y = (7.787 * var_Y) + (16 / 116)
if (var_Z > 0.008856) var_Z = var_Z ^ (1/3)
else var_Z = (7.787 * var_Z) + (16 / 116)
CIE-L* = (116 * var_Y) - 16
CIE-a* = 500 * (var_X - var_Y)
CIE-b* = 200 * (var_Y - var_Z)
CIE-L*ab —> XYZ
var_Y = (CIE-L* + 16) / 116
var_X = CIE-a* / 500 + var_Y
var_Z = var_Y - CIE-b* / 200
if (var_Y^3 > 0.008856) var_Y = var_Y^3
else var_Y = (var_Y - 16 / 116) / 7.787
if (var_X^3 > 0.008856) var_X = var_X^3
else var_X = (var_X - 16 / 116) / 7.787
if (var_Z^3 > 0.008856) var_Z = var_Z^3
else var_Z = (var_Z - 16 / 116) / 7.787
X = ref_X * var_X //ref_X = 95.047 Observer= 2°, Illuminant= D65
Y = ref_Y * var_Y //ref_Y = 100.000
Z = ref_Z * var_Z //ref_Z = 108.883
CIE-L*ab —> CIE-L*CH°
var_H = arc_tangent(CIE-b*, CIE-a*) //Quadrant by signs
if (var_H > 0) var_H = (var_H / PI) * 180
else var_H = 360 - (abs(var_H) / PI) * 180
CIE-L* = CIE-L*
CIE-C* = sqrt(CIE-a* ^ 2 + CIE-b* ^ 2)
CIE-H° = var_H
CIE-L*CH° —> CIE-L*ab
//CIE-H° = From 0 to 360°
CIE-L* = CIE-L*
CIE-a* = cos(degree_2_radian(CIE-H°)) * CIE-C*
CIE-b* = sin(degree_2_radian(CIE-H°)) * CIE-C*
XYZ —> CIE-L*uv
var_U = (4 * X) / (X + (15 * Y) + (3 * Z))
var_V = (9 * Y) / (X + (15 * Y) + (3 * Z))
var_Y = Y / 100
if (var_Y > 0.008856) var_Y = var_Y ^ (1/3)
else var_Y = (7.787 * var_Y) + (16 / 116)
ref_X = 95.047 //Observer= 2°, Illuminant= D65
ref_Y = 100.000
ref_Z = 108.883
ref_U = (4 * ref_X) / (ref_X + (15 * ref_Y) + (3 * ref_Z))
ref_V = (9 * ref_Y) / (ref_X + (15 * ref_Y) + (3 * ref_Z))
CIE-L* = (116 * var_Y) - 16
CIE-u* = 13 * CIE-L* * (var_U - ref_U)
CIE-v* = 13 * CIE-L* * (var_V - ref_V)
CIE-L*uv —> XYZ
var_Y = (CIE-L* + 16) / 116
if (var_Y^3 > 0.008856) var_Y = var_Y^3
else var_Y = (var_Y - 16 / 116) / 7.787
ref_X = 95.047 //Observer= 2°, Illuminant= D65
ref_Y = 100.000
ref_Z = 108.883
ref_U = (4 * ref_X) / (ref_X + (15 * ref_Y) + (3 * ref_Z))
ref_V = (9 * ref_Y) / (ref_X + (15 * ref_Y) + (3 * ref_Z))
var_U = CIE-u* / (13 * CIE-L*) + ref_U
var_V = CIE-v* / (13 * CIE-L*) + ref_V
Y = var_Y * 100
X = - (9 * Y * var_U) / ((var_U - 4) * var_V - var_U * var_V)
Z = (9 * Y - (15 * var_V * Y) - (var_V * X)) / (3 * var_V)
RGB —> HSL
var_R = (R / 255) //RGB values = From 0 to 255
var_G = (G / 255)
var_B = (B / 255)
var_Min = min(var_R, var_G, var_B) //Min. value of RGB
var_Max = max(var_R, var_G, var_B) //Max. value of RGB
del_Max = var_Max - var_Min //Delta RGB value
L = (var_Max + var_Min) / 2
if (del_Max == 0) //This is a gray, no chroma...
{
H = 0 //HSL results = From 0 to 1
S = 0
}
else //Chromatic data...
{
if (L < 0.5) S = del_Max / (var_Max + var_Min)
else S = del_Max / (2 - var_Max - var_Min)
del_R = (((var_Max - var_R) / 6) + (del_Max / 2)) / del_Max
del_G = (((var_Max - var_G) / 6) + (del_Max / 2)) / del_Max
del_B = (((var_Max - var_B) / 6) + (del_Max / 2)) / del_Max
if (var_R == var_Max) H = del_B - del_G
else if (var_G == var_Max) H = (1 / 3) + del_R - del_B
else if (var_B == var_Max) H = (2 / 3) + del_G - del_R
if (H < 0); H += 1
if (H > 1); H -= 1
}
HSL —> RGB
if (S == 0) //HSL values = From 0 to 1
{
R = L * 255 //RGB results = From 0 to 255
G = L * 255
B = L * 255
}
else
{
if (L < 0.5) var_2 = L * (1 + S)
else var_2 = (L + S) - (S * L)
var_1 = 2 * L - var_2
R = 255 * Hue_2_RGB(var_1, var_2, H + (1 / 3))
G = 255 * Hue_2_RGB(var_1, var_2, H)
B = 255 * Hue_2_RGB(var_1, var_2, H - (1 / 3))
}
Hue_2_RGB(v1, v2, vH) //Function Hue_2_RGB
{
if (vH < 0) vH += 1
if (vH > 1) vH -= 1
if ((6 * vH) < 1) return (v1 + (v2 - v1) * 6 * vH)
if ((2 * vH) < 1) return (v2)
if ((3 * vH) < 2) return (v1 + (v2 - v1) * ((2 / 3) - vH) * 6)
return (v1)
}
RGB —> HSV
var_R = (R / 255) //RGB values = From 0 to 255
var_G = (G / 255)
var_B = (B / 255)
var_Min = min(var_R, var_G, var_B) //Min. value of RGB
var_Max = max(var_R, var_G, var_B) //Max. value of RGB
del_Max = var_Max - var_Min //Delta RGB value
V = var_Max
if (del_Max == 0) //This is a gray, no chroma...
{
H = 0 //HSV results = From 0 to 1
S = 0
}
else //Chromatic data...
{
S = del_Max / var_Max
del_R = (((var_Max - var_R) / 6) + (del_Max / 2)) / del_Max
del_G = (((var_Max - var_G) / 6) + (del_Max / 2)) / del_Max
del_B = (((var_Max - var_B) / 6) + (del_Max / 2)) / del_Max
if (var_R == var_Max) H = del_B - del_G
else if (var_G == var_Max) H = (1 / 3) + del_R - del_B
else if (var_B == var_Max) H = (2 / 3) + del_G - del_R
if (H < 0); H += 1
if (H > 1); H -= 1
}
HSV —> RGB
if (S == 0) //HSV values = From 0 to 1
{
R = V * 255 //RGB results = From 0 to 255
G = V * 255
B = V * 255
}
else
{
var_h = H * 6
var_i = int(var_h) //Or... var_i = floor(var_h)
var_1 = V * (1 - S)
var_2 = V * (1 - S * (var_h - var_i))
var_3 = V * (1 - S * (1 - (var_h - var_i)))
if (var_i == 0) { var_r = V; var_g = var_3; var_b = var_1 }
else if (var_i == 1) { var_r = var_2; var_g = V; var_b = var_1 }
else if (var_i == 2) { var_r = var_1; var_g = V; var_b = var_3 }
else if (var_i == 3) { var_r = var_1; var_g = var_2; var_b = V }
else if (var_i == 4) { var_r = var_3; var_g = var_1; var_b = V }
else { var_r = V; var_g = var_1; var_b = var_2 }
R = var_r * 255 //RGB results = From 0 to 255
G = var_g * 255
B = var_b * 255
}
}
Range of HSL, HSB and HSV in popular applications
|
RGB —> CMY
//RGB values = From 0 to 255
C = 1 - (R / 255)
M = 1 - (G / 255)
Y = 1 - (B / 255)
CMY —> RGB
//CMY values = From 0 to 1
R = (1 - C) * 255
G = (1 - M) * 255
B = (1 - Y) * 255
CMY —> CMYK
//CMY values = From 0 to 1
var_K = 1
if (C < var_K) var_K = C
if (M < var_K) var_K = M
if (Y < var_K) var_K = Y
C = (C - var_K) / (1 - var_K)
M = (M - var_K) / (1 - var_K)
Y = (Y - var_K) / (1 - var_K)
K = var_K
CMYK —> CMY
//CMYK values = From 0 to 1
C = (C * (1 - K) + K)
M = (M * (1 - K) + K)
Y = (Y * (1 - K) + K)
XYZ (Tristimulus) Reference values of a perfect reflecting diffuser
Observer | 2° (CIE 1931) | 10° (CIE 1964) | ||||
Illuminant | X2 | Y2 | Z2 | X10 | Y10 | Z10 |
A (Incandescent) | 109.850 | 35.585 | 111.144 | 35.200 | ||
C | 98.074 | 118.232 | 97.285 | 116.145 | ||
D50 | 96.422 | 82.521 | 96.720 | 81.427 | ||
D55 | 95.682 | 92.149 | 95.799 | 90.926 | ||
D65 (Daylight) | 95.047 | 108.883 | 94.811 | 107.304 | ||
D75 | 94.972 | 122.638 | 94.416 | 120.641 | ||
F2 (Fluorescent) | 99.187 | 67.395 | 103.280 | 69.026 | ||
F7 | 95.044 | 108.755 | 95.792 | 107.687 | ||
F11 | 100.966 | 64.370 | 103.866 | 65.627 |
Дата добавления: 2015-07-10; просмотров: 218 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
What is CIE 1976 (L* a* b*) colour space? | | | Программа обработки векторной графики Corel Draw |