| Table of Contents / Filters / Color | Operators |
trans_from_rgb — Transform an image from the RGB color space to an arbitrary color space.
trans_from_rgb(ImageRed, ImageGreen, ImageBlue : ImageResult1, ImageResult2, ImageResult3 : ColorSpace : )
trans_from_rgb transforms an image from the RGB color space to an arbitrary color space (ColorSpace). The three channels of the image are passed as three separate images on input and output.
The operator trans_from_rgb supports the image types byte, uint2, int4, and real. In the case of int4 images, the images should not contain negative values. In the case of real images, all values should lay within 0 and 1. If not, the results of the transformation may not be reasonable.
Certain scalings are performed accordingly to the image type:
Considering byte and uint2 images, the domain of color space values is generally mapped to the full domain of [0..255] resp. [0..65535]. Because of this, the origin of signed values (e.g., CIELab) may not be at the center of the domain.
Hue values are represented by angles of [0..2PI] and are coded for the particular image types differently:
byte-images map the angle domain on [0..255].
uint2/int4-images are coded in angle minutes [0..21600].
real-images are coded in radians [0..2PI] .
Saturation values are represented by percentages of [0..100] and are coded for the particular image type differently:
byte-images map the saturation values to [0..255].
uint2/int4-images map the saturation values to [0..10000].
real-images map the saturation values to [0..1].
The following transformations are supported:
(All range of values are based on RGB values scaled to [0;1]. To obtain the range of values for a certain image type, they must be multiplied with the maximum of the image type, e.g., 255 in the case of a byte image)
|Y| |0.299 0.587 0.114| |R| |I| = |0.599 -0.276 -0.324| * |G| |Q| |0.214 -0.522 0.309| |B|
Y = [0;1], I = [-0.599;0.599], Q = [-0.522;0.522]
|Y| | 0.299 0.587 0.114| |R| |U| = |-0.147 -0.289 0.436| * |G| |V| | 0.615 -0.515 0.100| |B|
Y = [0;1], U = [-0.436;0.436], V = [-0.615;0.615]
|A | |0.30 0.59 0.11| |R| |Rg| = |0.50 -0.50 0.00| * |G| |Yb| |0.25 0.25 -0.50| |B|
A = [0;1], Rg = [-0.5,0.5], Yb = [-0.5, 0.5]
|X| |0.412453 0.357580 0.180423| |R|
|Y| = |0.212671 0.715160 0.072169| * |G|
|Z| |0.019334 0.119193 0.950227| |B|
The primary colors used correspond to sRGB respectively CIE Rec. 709. D65 is used as white point.
x y
red 0.6400 0.3300
green 0.3000 0.6000
blue 0.1500 0.0600
white 0.3127 0.3290
X:=[0;0.950456], Y:=[0;1], Z:=[0;1.088754]
min = min(R,G,B)
max = max(R,G,B)
L = (min + max) / 2
if (max == min)
H = 0
S = 0
else
if (L > 0.5)
S = (max - min) / (2 - max - min)
else
S = (max - min) / (max + min)
fi
if (R == max)
H = ((G - B) / (max - min)) * 60
elif (G == max)
H = (2 + (B - R) / (max - min)) * 60
elif (B == max)
H = (4 + (R - G) / (max - min)) * 60
fi
fi
H = [0;2pi], L = [0;1], S = [0;1]
|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 = ATan(M2/M1) S = Sqrt(M1*M1 + M2*M2) I = I1 / Sqrt(3)
H = [0;2pi], S= [0;Sqrt(2/3)], I = [0;1]
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)) * 60
elif (G == max)
H = (2 + (B - R) / (max - min)) * 60
elif (B == max)
H = (4 + (R - G) / (max - min)) * 60
fi
fi
H = [0;2pi], S = [0;1], V = [0;1]
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
A = (R + R - G - B) / 2
B = (R - G) * (R - G) + (R - B) * (G - B)
C = sqrt(B)
if (C == 0)
H = 0
else
H = acos(A / C)
fi
if (B > G)
H = 2 * pi - H
fi
fi
fi
I = [0;1], H = [0;2pi], S = [0;1]
|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] (Scaled to the maximum gray value in the case of byte and uint2. In the case of int4 L and a are scaled to the maximum gray value, b is scaled to the minimum gray value, such that the origin stays at 0.)
|I1| | 0.333 0.333 0.333| |R| |I2| = | 1.0 0.0 -1.0 | * |G| |I3| |-0.5 1.0 -0.5 | |B|
I1 = [0;1], I2 = [-1;1], I3 = [-1;1]
|X| |0.620 0.170 0.180| |R| |Y| = |0.310 0.590 0.110| * |G| |Z| |0.000 0.066 1.020| |B|
X = [0;0.970], Y = [0;1.010], Z = [0;1.086]
|X| |0.618 0.177 0.205| |R| |Y| = |0.299 0.587 0.114| * |G| |Z| |0.000 0.056 0.944| |B|
X = [0;1], Y = [0;1], Z = [0;1]
|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)
X:=[0;0.951], Y:=[0;1], Z:=[0;1.088]
As the calculations are made with a different numerical precision, the OpenCL implementation of the cielab transformation for images of type int4 is slightly less accurate than the pure C version.
Input image (red channel).
Input image (green channel).
Input image (blue channel).
Color-transformed output image (channel 1).
Color-transformed output image (channel 1).
Color-transformed output image (channel 1).
Color space of the output image.
Default value: 'hsv'
List of values: 'cielab', 'hsv', 'hsi', 'yiq', 'yuv', 'argyb', 'ciexyz', 'ciexyz2', 'ciexyz3', 'ciexyz4', 'hls', 'ihs', 'i1i2i3'
List of values (for compute devices): 'cielab', 'hsv', 'hsi'
* Transformation from rgb to hsv and conversely read_image(Image,'patras') disp_color(Image,WindowHandle) decompose3(Image,Rimage,Gimage,Bimage) trans_from_rgb(Rimage,Gimage,Bimage,Image1,Image2,Image3,'hsv') trans_to_rgb(Image1,Image2,Image3,ImageRed,ImageGreen,ImageBlue,'hsv') compose3(ImageRed,ImageGreen,ImageBlue,Multichannel) disp_color(Multichannel,WindowHandle)
trans_from_rgb returns 2 (H_MSG_TRUE) if all parameters are correct. If the input is empty the behaviour can be set via set_system(::'no_object_result',<Result>:). If necessary, an exception is raised.
linear_trans_color, rgb1_to_gray, rgb3_to_gray
ITU-R BT.470-6: “Conventional Television Systems”, 1998.
Foundation
| Table of Contents / Filters / Color | Operators |
| HALCON Reference Manual 10.0.2 | Copyright © 1996-2011 MVTec Software GmbH |