trans_to_rgb ( ImageInput1, ImageInput2, ImageInput3 : ImageRed, ImageGreen, ImageBlue : ColorSpace : )

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

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 following transformations are supported:

  'yiq'
     |R|   |0.999   0.962   0.615|   |Y|
     |G| = |0.949  -0.220  -0.732| * |I|
     |B|   |0.999  -1.101   1.706|   |Q|

  'yuv'
     |R|   |1.0     0.0     1.140|   |Y|
     |G| = |1.0    -0.394  -0.581| * |U|
     |B|   |1.0     2.032   0.0  |   |V|

  'argyb'
     |R|   |1.00   1.29   0.22|   |A |
     |G| = |1.00  -0.71   0.22| * |Rg|
     |B|   |1.00   0.29  -1.78|   |Yb|

  'ciexyz'
     |R|   | 2.750  -1.149  -0.426|   |X|
     |G| = |-1.118   2.026   0.033| * |Y|
     |B|   | 0.138  -0.333   1.104|   |Z|

  'cielab_new'
     (will be renamed to 'cielab' in upcoming major HALCON versions)

     fy = (L + 16) / 116
     fx = a/500 + fy
     fz = b/200 - fy

      X  = X_w * fx^3,                fx > 0.206893
      X  = (fx - 16/116) * X_w/7.787, sonst

      Y  = Y_w * fy^3,                fy > 0.206893
      Y  = (fy - 16/116) * Y_w/7.787, sonst

      Z  = Z_w * fz^3,                fz > 0.206893
      Z  = (fz - 16/116) * Z_w/7.787, sonst

     |R|   | 2.750  -1.149  -0.426|   |X|
     |G| = |-1.118   2.026   0.033| * |Y|
     |B|   | 0.138  -0.333   1.104|   |Z|

     Range of values:
       L := [0; 100], a := [-100.1; 83.0], b := [-106.8; 81.2]
       (for byte/int4 image types the ranges of values have to be scaled 
        to maximum or minimum gray value, respectively)

     Black point B: (Rb,Gb,Bb) = (0,0,0)
     white point W = (Rw,Gw,Bw), according to image type: 
       byte:(255,255,255), int4:(2^31-1,2^31-1,2^31-1), real:(1.0,1.0,1.0)

  'hls'
     Hi = integer(H * 6)
     Hf = fraction(H * 6)
     if (L <= 0.5)
        max = L * (S + 1)
     else
        max = L + S - (L * S)
     fi
     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
       elif (Hi == 1)
          R = min + (1 - Hf) * (max - min)
          G = max
          B = min
       elif (Hi == 2)
          R = min
          G = max
          B = min + Hf * (max - min)
       elif (Hi == 3)
          R = min
          G = min + (1 - Hf) * (max - min)
          B = max
       elif (Hi == 4)
          R = min + Hf * (max - min)
          G = min
          B = max
       elif (Hi == 5)
          R = max
          G = min
          B = min + (1 - Hf) * (max - min)
       fi
     fi           

  'hsi'
     M1 = S * cos(H)
     M2 = S * sin(H)
     I1 = I / sqrt(3)
     |R|   | 2/sqrt(6)   0           1/sqrt(3)|   |M1|
     |G| = |-1/sqrt(6)   1/sqrt(2)   1/sqrt(3)| * |M2|
     |B|   |-1/sqrt(6)  -1/sqrt(2)   1/sqrt(3)|   |I1|

  'hsv'
     if (S == 0)
        R = V
        G = V
        B = V
     else
        Hi = integer(H)
        Hf = fraction(H)
        if (Hi == 0)
           R = V
           G = V * (1 - (S * (1 - Hf)))
           B = V * (1 - S)
        elif (Hi == 1)
           R = V * (1 - (S * Hf))
           G = V
           B = V * (1 - S)
        elif (Hi == 2)
           R = V * (1 - S)
           G = V
           B = V * (1 - (S * (1 - Hf)))
        elif (Hi == 3)
           R = V * (1 - S)
           G = V * (1 - (S * Hf))
           B = V
        elif (Hi == 4)
           R = V * (1 - (S * (1 - Hf)))
           G = V * (1 - S)
           B = V
        elif (Hi == 5)
           R = V
           G = V * (1 - S)
           B = V * (1 - (S * Hf))
        fi
     fi
If one of the following conditions is fulfilled, certain scalings are expected accordingly to the image type:
  - Considering byte images, the domain of color space values is generally
    expected to be spread  to the full domain of [0..255]. The origin of 
    signed values must be shifted to 128.

  - 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].
      + int4-images are coded in angle minutes [0..21600].
      + real-images are coded in radians [0..2\pi].


Parameters

ImageInput1 (input_object)
image(-array) -> object : byte / int4 / real
Input image (channel 1).

ImageInput2 (input_object)
image(-array) -> object : byte / int4 / real
Input image (channel 2).

ImageInput3 (input_object)
image(-array) -> object : byte / int4 / real
Input image (channel 3).

ImageRed (output_object)
image(-array) -> object : byte / int4 / real
Red channel.

ImageGreen (output_object)
image(-array) -> object : byte / int4 / real
Green channel.

ImageBlue (output_object)
image(-array) -> object : byte / int4 / real
Blue channel.

ColorSpace (input_control)
string -> string
Color space of the input image.
Default value: 'hsv'
List of values: 'hsi', 'yiq', 'yuv', 'argyb', 'ciexyz', 'cielab_new', 'hls', 'hsv'


Example
/* Tranformation 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).

Result

trans_to_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 handling is raised.


Parallelization Information

trans_to_rgb is reentrant and automatically parallelized (on tuple level, domain level).


Possible Predecessors

decompose3


Possible Successors

compose3, disp_color


See also

decompose3


Module

Foundation



Copyright © 1996-2008 MVTec Software GmbH