trans_from_rgb— 将图像从 RGB 色彩空间转换为任意色彩空间。
(所有值范围均基于缩放为 [0; 1] 的 RGB 值。自动获取特定图像类型的值范围,则它们必须为乘以 image 类型的最大值,例如,在这种情况下为 255 字节图像)
read_image (Image, 'E:/20240911/Img/00FMB0HU000004E9A0000932_aa19606.000_20240911000353_A.jpg')
decompose3 (Image, Red, Green, Blue)
*'hsv'
Min := min([R, G, B])
Max := max([R, G, B])
V := Max
if (Max == Min)
S := 0
H := 0
else
S := (Max - Min) / Max
if (R == Max)
H := ((G - B) / (Max - Min)) * rad(60)
elseif (G == Max)
H := (2 + (B - R) / (Max - Min)) * rad(60)
elseif (B == Max)
H := (4 + (R - G) / (Max - Min)) * rad(60)
endif
endif
Range of values:
H = [0; 2pi[, S = [0; 1], V = [0; 1]
trans_from_rgb (Red, Green, Blue, H, S, V, 'hsv')
dev_display (H)
dev_display (S)
dev_display (V)
*'hsi'
|M1| |2/sqrt(6) -1/sqrt(6) -1/sqrt(6)| |R|
|M2| = |0 1/sqrt(2) -1/sqrt(2)| * |G|
|I1| |1/sqrt(3) 1/sqrt(3) 1/sqrt(3)| |B|
H = atan2(M2,M1)
S = sqrt(M1*M1 + M2*M2)
I = I1 / sqrt(3)
Range of values:
H = [0; 2pi[, S= [0; sqrt(2/3)], I = [0; 1]
trans_from_rgb (Red, Green, Blue, H1, S1, V1, 'hsi')
dev_display (H1)
dev_display (S1)
dev_display (V1)
*'yiq'
|Y| |0.299 0.587 0.114| |R|
|I| = |0.599 -0.276 -0.324| * |G|
|Q| |0.214 -0.522 0.309| |B|
Range of values:
Y = [0; 1], I = [-0.599; 0.599], Q = [-0.522; 0.522]
trans_from_rgb (Red, Green, Blue, H2, S2, V2, 'yiq')
dev_display (H2)
dev_display (S2)
dev_display (V2)
*'yuv'
|Y| | 0.299 0.587 0.114| |R|
|U| = |-0.147 -0.289 0.436| * |G|
|V| | 0.615 -0.515 -0.100| |B|
Range of values:
Y = [0; 1], U = [-0.436; 0.436], V = [-0.615; 0.615]
trans_from_rgb (Red, Green, Blue, H3, S3, V3, 'yuv')
dev_display (H3)
dev_display (S3)
dev_display (V3)
*'argyb'
|A | |0.30 0.59 0.11| |R|
|Rg| = |0.50 -0.50 0.00| * |G|
|Yb| |0.25 0.25 -0.50| |B|
Range of values:
A = [0; 1], Rg = [-0.5, 0.5], Yb = [-0.5, 0.5]
trans_from_rgb (Red, Green, Blue, H4, S4, V4, 'argyb')
dev_display (H4)
dev_display (S4)
dev_display (V4)
*'ciexyz'
|X| |0.412453 0.357580 0.180423| |R|
|Y| = |0.212671 0.715160 0.072169| * |G|
|Z| |0.019334 0.119193 0.950227| |B|
使用的原色对应于 sRGB 和 CIE Rec. 709。 D65 用作白点。
使用的原色 (x, y, z):
x y z
red 0.6400 0.3300 0.0300
green 0.3000 0.6000 0.1000
blue 0.1500 0.0600 0.7900
white 0.3127 0.3290 0.3583
取值范围:
X:=[0; 0.950456], Y:=[0; 1], Z:=[0; 1.088754]
trans_from_rgb (Red, Green, Blue, H5, S5, V5, 'ciexyz')
dev_display (H5)
dev_display (S5)
dev_display (V5)
*'CIELAB'
|X| |0.412453 0.357580 0.180423| |R|
|Y| = |0.212671 0.715160 0.072169| * |G|
|Z| |0.019334 0.119193 0.950227| |B|
L = 116 * f(Y/Yw) - 16
a = 500 * (f(X/Xw) - f(Y/Yw))
b = 200 * (f(Y/Yw) - f(Z/Zw))
f(t) = t^(1/3), t > (24/116)^3
f(t) = (841/108)*t + 16/116, otherwise.
Black point B: (Rb, Gb, Bb) = (0, 0, 0)
White point W = (Rw, Gw, Bw), according to image type:
byte:=(255, 255, 255), uint2:=(2^16-1, 2^16-1, 2^16-1),
int4:=(2^31-1, 2^31-1, 2^31-1), real:=(1.0, 1.0, 1.0)
取值范围:
L := [0; 100], a := [-86.1813; 98.2352], b := [-107.8617; 94.4758]
(在 byte 和 uint2 的情况下,缩放到最大灰度值。 在 int4 的情况下,L 和 a 被缩放到最大灰度值, b 缩放到最小灰度值,以便原点保持为0。
trans_from_rgb (Red, Green, Blue, H6, S6, V6, 'cielab')
dev_display (H6)
dev_display (S6)
dev_display (V6)
*'cielchab'
|X| |0.412453 0.357580 0.180423| |R|
|Y| = |0.212671 0.715160 0.072169| * |G|
|Z| |0.019334 0.119193 0.950227| |B|
L = 116 * f(Y/Yw) - 16
a = 500 * (f(X/Xw) - f(Y/Yw))
b = 200 * (f(Y/Yw) - f(Z/Zw))
C_ab = sqrt(a^2+b^2)
h_ab = atan2(b,a)
f(t) = t^(1/3), t > (24/116)^3
f(t) = (841/108)*t + 16/116, otherwise.
h_ab lies between 0° and 90° if a and b are both positive,
between 90° and 180° if a is negative and b is positive,
between 180° and 270° if a and b are both negative, and
between 270° and 360° if a is positive and b is negative.
Black point B: (Rb, Gb, Bb) = (0, 0, 0)
White point W = (Rw, Gw, Bw), according to image type:
byte:=(255, 255, 255), uint2:=(2^16-1, 2^16-1, 2^16-1),
int4:=(2^31-1, 2^31-1, 2^31-1), real:=(1.0, 1.0, 1.0)
Range of values:
L := [0; 100], C := [0; 133.8086], h := [0; 360]
(在 byte 和 uint2 的情况下,缩放到最大灰度值。 在 int4 的情况下,L 和 C 被缩放到最大灰度值, 而 h 以 arcs 秒为单位
trans_from_rgb (Red, Green, Blue, H7, S7, V7, 'cielchab')
dev_display (H7)
dev_display (S7)
dev_display (V7)
*'cieluv'
|X| |0.412453 0.357580 0.180423| |R|
|Y| = |0.212671 0.715160 0.072169| * |G|
|Z| |0.019334 0.119193 0.950227| |B|
u' = 4*X / (X + 15*Y + 3*Z)
v' = 9*Y / (X + 15*Y + 3*Z)
uw' = 4*Xw / (Xw + 15*Yw + 3*Zw)
vw' = 9*Yw / (Xw + 15*Yw + 3*Zw)
L = 116 * f(Y/Yw) - 16
u = 13 * L * (u' - uw')
v = 13 * L * (v' - vw')
f(t) = t^(1/3), t > (24/116)^3
f(t) = (841/108)*t + 16/116, otherwise.
Black point B: (Rb, Gb, Bb) = (0, 0, 0)
White point W = (Rw, Gw, Bw), according to image type:
byte:=(255, 255, 255), uint2:=(2^16-1, 2^16-1, 2^16-1),
int4:=(2^31-1, 2^31-1, 2^31-1), real:=(1.0, 1.0, 1.0)
取值范围:
L := [0; 100], u := [-83.0774; 175.0148], v := [-134.1008; 107.3923]
(在 byte 和 uint2 的情况下,缩放到最大灰度值。 如果是 int4 L,并且 u 被缩放到最大灰度值, v 缩放到最小灰度值,以便原点保持 为 0。
trans_from_rgb (Red, Green, Blue, H8, S8, V8, 'cieluv')
dev_display (H8)
dev_display (S8)
dev_display (V8)
*'cielchuv'
|X| |0.412453 0.357580 0.180423| |R|
|Y| = |0.212671 0.715160 0.072169| * |G|
|Z| |0.019334 0.119193 0.950227| |B|
u' = 4*X / (X + 15*Y + 3*Z)
v' = 9*Y / (X + 15*Y + 3*Z)
uw' = 4*Xw / (Xw + 15*Yw + 3*Zw)
vw' = 9*Yw / (Xw + 15*Yw + 3*Zw)
L = 116 * f(Y/Yw) - 16
u = 13 * L * (u' - uw')
v = 13 * L * (v' - vw')
C_uv = sqrt(u^2+v^2)
h_uv = atan2(v,u)
f(t) = t^(1/3), t > (24/116)^3
f(t) = (841/108)*t + 16/116, otherwise.
h_uv lies between 0° and 90° if u and v are both positive,
between 90° and 180° if u is negative and v is positive,
between 180° and 270° if u and v are both negative, and
between 270° and 360° if u is positive and v is negative.
Black point B: (Rb, Gb, Bb) = (0, 0, 0)
White point W = (Rw, Gw, Bw), according to image type:
byte:=(255, 255, 255), uint2:=(2^16-1, 2^16-1, 2^16-1),
int4:=(2^31-1, 2^31-1, 2^31-1), real:=(1.0, 1.0, 1.0)
Range of values:
L := [0; 100], C := [0; 179.0402], h := [0; 360[
在 byte 和 uint2 的情况下,缩放到最大灰度值。 在 int4 的情况下,
L 和 C 被缩放到最大灰度值, 而 h 以 arcs 秒为单位。)
trans_from_rgb (Red, Green, Blue, H9, S9, V9, 'cielchuv')
dev_display (H9)
dev_display (S9)
dev_display (V9)
*'ciexyz2'
|X| |0.620 0.170 0.180| |R|
|Y| = |0.310 0.590 0.110| * |G|
|Z| |0.000 0.066 1.020| |B|
Range of values:
X = [0; 0.970], Y = [0; 1.010], Z = [0; 1.086]
trans_from_rgb (Red, Green, Blue, H10, S10, V10, 'ciexyz2')
dev_display (H10)
dev_display (S10)
dev_display (V10)
*'ciexyz3'
|X| |0.618 0.177 0.205| |R|
|Y| = |0.299 0.587 0.114| * |G|
|Z| |0.000 0.056 0.944| |B|
Range of values:
X = [0; 1], Y = [0; 1], Z = [0; 1]
trans_from_rgb (Red, Green, Blue, H11, S11, V11, 'ciexyz3')
dev_display (H11)
dev_display (S11)
dev_display (V11)
*'ciexyz4'
|X| |0.476 0.299 0.175| |R|
|Y| = |0.262 0.656 0.082| * |G|
|Z| |0.020 0.161 0.909| |B|
Primary colors (x, y, z):
red:=(0.628, 0.346, 0.026), green:=(0.268, 0.588, 0.144),
blue:=(0.150, 0.070, 0.780), white65:=(0.313, 0.329, 0.358)
Used primary colors (x, y, z):
x y z
red 0.628 0.346 0.026
green 0.268 0.588 0.144
blue 0.150 0.070 0.780
white65 0.313 0.329 0.358
Range of values:
X:=[0; 0.951], Y:=[0; 1], Z:=[0; 1.088]
trans_from_rgb (Red, Green, Blue, H12, S12, V12, 'ciexyz4')
dev_display (H12)
dev_display (S12)
dev_display (V12)
*'lms'
|L| |0.390469, 0.549910, 0.008901| |R|
|M| = |0.070925, 0.963118, 0.001358| * |G|
|S| |0.023143, 0.128013, 0.935976| |B|
This conceptually is a transformation from RGB to CIE XYZ (see 'ciexyz' above) followed by a transformation from CIE XYZ to LMS.
Range of values:
L:=[0; 0.949280], M:=[0; 1.035401], S:=[0; 1.087132]
trans_from_rgb (Red, Green, Blue, H13, S13, V13, 'lms')
dev_display (H13)
dev_display (S13)
dev_display (V13)
*'i1i2i3'
|I1| | 0.333 0.333 0.333| |R|
|I2| = | 1.0 0.0 -1.0 | * |G|
|I3| |-0.5 1.0 -0.5 | |B|
Range of values:
I1 = [0; 1], I2 = [-1; 1], I3 = [-1; 1]
trans_from_rgb (Red, Green, Blue, H14, S14, V14, 'i1i2i3')
dev_display (H14)
dev_display (S14)
dev_display (V14)
*'ihs'
Min := min([R, G, B])
Max := max([R, G, B])
I := (R + G + B) / 3
if (I == 0)
H := 0
S := 1
else
S := 1 - Min / I
if (S == 0)
H := 0
else
X := (R + R - G - B) / 2
Y := (R - G) * (R - G) + (R - B) * (G - B)
Z := sqrt(Y)
if (Z == 0)
H := 0
else
H := acos(X / Z)
endif
if (B > G)
H := rad(360) - H
endif
endif
endif
Range of values:
I = [0; 1], H = [0; 2pi[, S = [0; 1]
trans_from_rgb (Red, Green, Blue, H15, S15, V15, 'ihs')
dev_display (H15)
dev_display (S15)
dev_display (V15)