trans_to_rgb
— Transform an image from an arbitrary color space to the RGB color space.
trans_to_rgb(ImageInput1, ImageInput2, ImageInput3 : ImageRed, ImageGreen, ImageBlue : ColorSpace : )
trans_to_rgb
transforms an image from an arbitrary color
space (ColorSpace
) to the RGB color space. The three
channels of the image are passed as three separate images on input
and output.
The operator trans_to_rgb
supports the image types byte
,
uint2
, int4
, and real
.
The domain of the input images must match the
domain provided by a corresponding transformation with
trans_from_rgb
. If not, the results of the transformation may not
be reasonable.
This includes some scalings in the case of certain image types and transformations:
Considering byte
and uint2
images, the domain
of color space values is expected to be spread to the full
domain of [0..255] or [0..65535], respectively.
This includes a shift in the case of signed values, such that
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..2[ and are coded for the particular image types differently:
byte
-images map the angle domain on
[0..255].
uint2
/int4
-images are coded in
minutes of arc [0..21600[, except for the transformations
'cielchab' and 'cielchuv' for
int4
-images, where they are coded in
seconds of arc [0..1296000[.
real
-images are coded in radians
[0..2[, except for the transformations
'cielchab' and 'cielchuv' , where the
standards ISO 11664-4:2008 and ISO 11664-5:2009 require the
hue to be specified in degrees.
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].
Supported are the transformations listed below. Note, all domains are based on RGB values scaled to [0; 1]. To obtain the domain of a certain image type, they must be scaled accordingly with the value range. Due to different precision the values obtained using the given equations may slightly differ from the values returned by the operator.
Value range: , ,
Note, this implies that , , and are not independent of each other.
Value range:
Value range: , ,
Value range:
Black point B: (, , ) = (0, 0, 0)
White point W (according to image type):
byte
: (, , ) =
(255, 255, 255)
uint2
: (, , ) =
(, ,
)
int4
: (, , ) =
(, ,
)
real
: (, , ) =
(1.0, 1.0, 1.0)
Value range:
,
,
(byte
and uint2
:
scaled to the maximum gray value.
int4
:
is scaled to the maximum gray value,
and is scaled to the minimum gray value,
such that the origin stays at 0.)
Black point B: (, , ) = (0, 0, 0)
White point W (according to image type):
byte
: (, , ) =
(255, 255, 255)
uint2
: (, , ) =
(, ,
)
int4
: (, , ) =
(, ,
)
real
: (, , ) =
(1.0, 1.0, 1.0)
Value range:
,
,
(byte
:
scaled to the maximum gray value.
uint2
:
and are scaled to the maximum gray value,
is given in minutes of arc.
int4
:
and are scaled to the maximum gray value,
is given in seconds of arc.)
Black point B: (, , ) = (0, 0, 0)
White point W (according to image type):
byte
: (, , ) =
(255, 255, 255)
uint2
: (, , ) =
(, ,
)
int4
: (, , ) =
(, ,
)
real
: (, , ) =
(1.0, 1.0, 1.0)
Value range:
,
,
(byte
and uint2
:
scaled to the maximum gray value.
int4
:
are scaled to the maximum gray value,
and are scaled to the minimum gray value,
such that the origin stays at 0.)
Black point B: (, , ) = (0, 0, 0)
White point W (according to image type):
byte
: (, , ) =
(255, 255, 255)
uint2
: (, , ) =
(, ,
)
int4
: (, , ) =
(, ,
)
real
: (, , ) =
(1.0, 1.0, 1.0)
Value range:
,
,
(byte
:
scaled to the maximum gray value.
uint2
:
and are scaled to the maximum gray value,
is given in minutes of arc.
int4
:
and are scaled to the maximum gray value,
is given in seconds of arc.)
Hi := floor(H/rad(60)) Hf := H/rad(60) - Hi if (L <= 0.5) Max := L * (S + 1) else Max := L + S - (L * S) endif Min := 2 * L - Max if (S == 0) R := L G := L B := L else if (Hi == 0) R := Max G := Min + Hf * (Max - Min) B := Min elseif (Hi == 1) R := Min + (1 - Hf) * (Max - Min) G := Max B := Min elseif (Hi == 2) R := Min G := Max B := Min + Hf * (Max - Min) elseif (Hi == 3) R := Min G := Min + (1 - Hf) * (Max - Min) B := Max elseif (Hi == 4) R := Min + Hf * (Max - Min) G := Min B := Max elseif (Hi == 5) R := Max G := Min B := Min + (1 - Hf) * (Max - Min) endif endif
Value range: , ,
if (S == 0) R := V G := V B := V else Hi := floor(H/rad(60)) Hf := H/rad(60) - Hi if (Hi == 0) R := V G := V * (1 - (S * (1 - Hf))) B := V * (1 - S) elseif (Hi == 1) R := V * (1 - (S * Hf)) G := V B := V * (1 - S) elseif (Hi == 2) R := V * (1 - S) G := V B := V * (1 - (S * (1 - Hf))) elseif (Hi == 3) R := V * (1 - S) G := V * (1 - (S * Hf)) B := V elseif (Hi == 4) R := V * (1 - (S * (1 - Hf))) G := V * (1 - S) B := V elseif (Hi == 5) R := V G := V * (1 - S) B := V * (1 - (S * Hf)) endif endif
Value range: , ,
Value range: , ,
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.
ImageInput1
(input_object) singlechannelimage(-array) →
object (byte / uint2 / int4 / real)
Input image (channel 1).
ImageInput2
(input_object) singlechannelimage(-array) →
object (byte / uint2 / int4 / real)
Input image (channel 2).
ImageInput3
(input_object) singlechannelimage(-array) →
object (byte / uint2 / int4 / real)
Input image (channel 3).
ImageRed
(output_object) singlechannelimage(-array) →
object (byte / uint2 / int4 / real)
Red channel.
ImageGreen
(output_object) singlechannelimage(-array) →
object (byte / uint2 / int4 / real)
Green channel.
ImageBlue
(output_object) singlechannelimage(-array) →
object (byte / uint2 / int4 / real)
Blue channel.
ColorSpace
(input_control) string →
(string)
Color space of the input image.
Default: 'hsv'
List of values: 'argyb' , 'cielab' , 'cielchab' , 'cielchuv' , 'cieluv' , 'ciexyz' , 'ciexyz4' , 'hls' , 'hsi' , 'hsv' , 'lms' , 'yiq' , 'yuv'
List of values (for compute devices): 'cielab' , 'cielchab' , 'cieluv' , 'cielchuv' , 'hsv' , 'hsi'
* Transformation from rgb to hsv and conversely read_image(Image,'patras') dev_display(Image) decompose3(Image, Image1, Image2, Image3) trans_from_rgb(Image1,Image2,Image3,ImageH,ImageS,ImageV,'hsv') trans_to_rgb(ImageH,ImageS,ImageV,ImageR,ImageG,ImageB,'hsv') compose3(ImageR,ImageG,ImageB,Multichannel) dev_display(Multichannel)
trans_to_rgb
returns 2 (
H_MSG_TRUE)
if all parameters are
correct. If the input is empty the behavior can be set via
set_system(::'no_object_result', <Result>:)
. If
necessary, an exception is raised.
ITU-R BT.470-6: “Conventional Television Systems”, 1998.
ISO 11664-4:2008: “Colorimetry --- Part 4: CIE 1976 L*a*b* Colour
space”, 2008.
ISO 11664-5:2009: “Colorimetry --- Part 5: CIE 1976 L*u*v* Colour
space and u',v' uniform chromaticity scale diagram”, 2009.
Foundation