Operator Reference

trans_from_rgbtrans_from_rgbTransFromRgbTransFromRgbtrans_from_rgb (Operator)

trans_from_rgbtrans_from_rgbTransFromRgbTransFromRgbtrans_from_rgb — Transform an image from the RGB color space to an arbitrary color space.

Signature

Herror trans_from_rgb(const Hobject ImageRed, const Hobject ImageGreen, const Hobject ImageBlue, Hobject* ImageResult1, Hobject* ImageResult2, Hobject* ImageResult3, const char* ColorSpace)

Herror T_trans_from_rgb(const Hobject ImageRed, const Hobject ImageGreen, const Hobject ImageBlue, Hobject* ImageResult1, Hobject* ImageResult2, Hobject* ImageResult3, const Htuple ColorSpace)

void TransFromRgb(const HObject& ImageRed, const HObject& ImageGreen, const HObject& ImageBlue, HObject* ImageResult1, HObject* ImageResult2, HObject* ImageResult3, const HTuple& ColorSpace)

HImage HImage::TransFromRgb(const HImage& ImageGreen, const HImage& ImageBlue, HImage* ImageResult2, HImage* ImageResult3, const HString& ColorSpace) const

HImage HImage::TransFromRgb(const HImage& ImageGreen, const HImage& ImageBlue, HImage* ImageResult2, HImage* ImageResult3, const char* ColorSpace) const

HImage HImage::TransFromRgb(const HImage& ImageGreen, const HImage& ImageBlue, HImage* ImageResult2, HImage* ImageResult3, const wchar_t* ColorSpace) const   ( Windows only)

def trans_from_rgb(image_red: HObject, image_green: HObject, image_blue: HObject, color_space: str) -> Tuple[HObject, HObject, HObject]

Description

trans_from_rgbtrans_from_rgbTransFromRgbTransFromRgbtrans_from_rgb transforms an image from the RGB color space to an arbitrary color space (ColorSpaceColorSpaceColorSpacecolorSpacecolor_space). The three channels of the image are passed as three separate images on input and output.

The operator trans_from_rgbtrans_from_rgbTransFromRgbTransFromRgbtrans_from_rgb supports the image types byte, uint2, int4, and real. 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] or [0..65535], respectively. 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..2 [ and are coded for the particular image types differently:

    • byte-images map the angle domain to [0..255].

    • uint2/int4-images are coded in minutes of arc [0..21600[, except for the transformations 'cielchab'"cielchab""cielchab""cielchab""cielchab" and 'cielchuv'"cielchuv""cielchuv""cielchuv""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'"cielchab""cielchab""cielchab""cielchab" and 'cielchuv'"cielchuv""cielchuv""cielchuv""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 differently for the particular image type:

    • byte-images map the saturation values to [0..255].

    • uint2/int4 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.

'yiq'

Value range: , ,

'yuv'

Note, this implies that , , and are not independent of each other.

Value range: , ,

'argyb'

Value range: , ,

'ciexyz'

The primary colors used correspond to sRGB respectively CIE Rec. 709. D65 is used as white point.

Used primary colors (x, y, z):

Value range: , ,

'hls'

  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)
     endif
     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
  
Value range: , ,
'hsi'

Value range: , ,

'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
  
Value range: , ,
'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
  
Value range: , ,
'cielab'

where

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 are scaled to the minimum gray value, such that the origin stays at 0.)

'cielchab'

where

lies

  • between 0° and 90° if and are both positive,

  • between 90° and 180° if is negative and is positive,

  • between 180° and 270° if and are both negative, and

  • between 270° and 360° if is positive and is negative.

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.)

'cieluv'

where

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 are scaled to the minimum gray value, such that the origin stays at 0.)

'cielchuv'

where

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.)

'i1i2i3'

Value range: , ,

'ciexyz2'

Value range: , ,

'ciexyz3'

Value range: , ,

'ciexyz4'

Used primary colors (x, y, z):

Value range: , ,

'lms'

This conceptually is a transformation from RGB to CIE XYZ (see 'ciexyz'"ciexyz""ciexyz""ciexyz""ciexyz" above) followed by a transformation from CIE XYZ to LMS.

Value range: , ,

Attention

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.

Execution Information

  • Supports OpenCL compute devices.
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).
  • Multithreading scope: global (may be called from any thread).
  • Automatically parallelized on tuple level.
  • Automatically parallelized on domain level.

Parameters

ImageRedImageRedImageRedimageRedimage_red (input_object)  singlechannelimage(-array) objectHImageHObjectHObjectHobject (byte / uint2 / int4 / real)

Input image (red channel).

ImageGreenImageGreenImageGreenimageGreenimage_green (input_object)  singlechannelimage(-array) objectHImageHObjectHObjectHobject (byte / uint2 / int4 / real)

Input image (green channel).

ImageBlueImageBlueImageBlueimageBlueimage_blue (input_object)  singlechannelimage(-array) objectHImageHObjectHObjectHobject (byte / uint2 / int4 / real)

Input image (blue channel).

ImageResult1ImageResult1ImageResult1imageResult1image_result_1 (output_object)  singlechannelimage(-array) objectHImageHObjectHObjectHobject * (byte / uint2 / int4 / real)

Color-transformed output image (channel 1).

ImageResult2ImageResult2ImageResult2imageResult2image_result_2 (output_object)  singlechannelimage(-array) objectHImageHObjectHObjectHobject * (byte / uint2 / int4 / real)

Color-transformed output image (channel 1).

ImageResult3ImageResult3ImageResult3imageResult3image_result_3 (output_object)  singlechannelimage(-array) objectHImageHObjectHObjectHobject * (byte / uint2 / int4 / real)

Color-transformed output image (channel 1).

ColorSpaceColorSpaceColorSpacecolorSpacecolor_space (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Color space of the output image.

Default: 'hsv' "hsv" "hsv" "hsv" "hsv"

List of values: 'argyb'"argyb""argyb""argyb""argyb", 'cielab'"cielab""cielab""cielab""cielab", 'cielchab'"cielchab""cielchab""cielchab""cielchab", 'cielchuv'"cielchuv""cielchuv""cielchuv""cielchuv", 'cieluv'"cieluv""cieluv""cieluv""cieluv", 'ciexyz'"ciexyz""ciexyz""ciexyz""ciexyz", 'ciexyz2'"ciexyz2""ciexyz2""ciexyz2""ciexyz2", 'ciexyz3'"ciexyz3""ciexyz3""ciexyz3""ciexyz3", 'ciexyz4'"ciexyz4""ciexyz4""ciexyz4""ciexyz4", 'hls'"hls""hls""hls""hls", 'hsi'"hsi""hsi""hsi""hsi", 'hsv'"hsv""hsv""hsv""hsv", 'i1i2i3'"i1i2i3""i1i2i3""i1i2i3""i1i2i3", 'ihs'"ihs""ihs""ihs""ihs", 'lms'"lms""lms""lms""lms", 'yiq'"yiq""yiq""yiq""yiq", 'yuv'"yuv""yuv""yuv""yuv"

List of values (for compute devices): 'cielab'"cielab""cielab""cielab""cielab", 'cielchab'"cielchab""cielchab""cielchab""cielchab", 'cieluv'"cieluv""cieluv""cieluv""cieluv", 'cielchuv'"cielchuv""cielchuv""cielchuv""cielchuv", 'hsv'"hsv""hsv""hsv""hsv", 'hsi'"hsi""hsi""hsi""hsi"

Example (HDevelop)

* 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)

Example (C)

/* 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);

Example (HDevelop)

* 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)

Example (HDevelop)

* 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)

Result

trans_from_rgbtrans_from_rgbTransFromRgbTransFromRgbtrans_from_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>:)set_system("no_object_result", <Result>)SetSystem("no_object_result", <Result>)SetSystem("no_object_result", <Result>)set_system("no_object_result", <Result>). If necessary, an exception is raised.

Possible Predecessors

decompose3decompose3Decompose3Decompose3decompose3

Possible Successors

compose3compose3Compose3Compose3compose3

Alternatives

linear_trans_colorlinear_trans_colorLinearTransColorLinearTransColorlinear_trans_color, rgb1_to_grayrgb1_to_grayRgb1ToGrayRgb1ToGrayrgb1_to_gray, rgb3_to_grayrgb3_to_grayRgb3ToGrayRgb3ToGrayrgb3_to_gray

See also

trans_to_rgbtrans_to_rgbTransToRgbTransToRgbtrans_to_rgb

References

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.

Module

Foundation