Herror ::trans_to_rgb (
    Hobject ImageInput1,
    Hobject ImageInput2,
    Hobject ImageInput3,
    Hobject *ImageRed,
    Hobject *ImageGreen,
    Hobject *ImageBlue,
    const HTuple &ColorSpace
)
HImage HImage::TransToRgb (
    const HImageArray &ImageInput2,
    const HImageArray &ImageInput3,
    HImage *ImageGreen,
    HImage *ImageBlue,
    const HTuple &ColorSpace
) const
HImageArray HImageArray::TransToRgb (
    const HImageArray &ImageInput2,
    const HImageArray &ImageInput3,
    HImageArray *ImageGreen,
    HImageArray *ImageBlue,
    const HTuple &ColorSpace
) const

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|

  '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)
        if (H == 0)
           R = V
           G = V
           B = V
        else
           R = 0
           G = 0
           B = 0
        fi
     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 necessary, certain scalings are performed, e.g., for byte-images [0..1] -> [0..255]. In the explanation above all input and output values, including angles, are assumed to be in the range [0..1].


Parameters

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

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

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

ImageRed (output_object)
image(-array) -> Hobject * : HImage(Array) ( byte / int4 / real )
Red channel.

ImageGreen (output_object)
image(-array) -> Hobject * : HImage(Array) ( byte / int4 / real )
Green channel.

ImageBlue (output_object)
image(-array) -> Hobject * : HImage(Array) ( byte / int4 / real )
Blue channel.

ColorSpace (input_control)
string -> HTuple.char *
Color space of the input image.
Default value: 'hsv'
List of values: 'hsi', 'yiq', '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 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.


Possible Predecessors

::decompose3


Possible Successors

::compose3, ::disp_color


See also

::decompose3


Module

Image filters



Copyright © 1996-2002 MVTec Software GmbH