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|

  '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 * sin(H)
     M2 = S * cos(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].

  - For int4-images a domain of [0..1] of transformed values 
    imust be spread to [0..10000].


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', '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

Image filters



Copyright © 1996-2005 MVTec Software GmbH