Herror ::trans_from_rgb (
    Hobject ImageRed,
    Hobject ImageGreen,
    Hobject ImageBlue,
    Hobject *ImageResult1,
    Hobject *ImageResult2,
    Hobject *ImageResult3,
    const HTuple &ColorSpace
)
HImage HImage::TransFromRgb (
    const HImageArray &ImageGreen,
    const HImageArray &ImageBlue,
    HImage *ImageResult2,
    HImage *ImageResult3,
    const HTuple &ColorSpace
) const
HImageArray HImageArray::TransFromRgb (
    const HImageArray &ImageGreen,
    const HImageArray &ImageBlue,
    HImageArray *ImageResult2,
    HImageArray *ImageResult3,
    const HTuple &ColorSpace
) const

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

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

The following transformations are supported:

  'yiq'
     |Y|   |0.299   0.587   0.144|   |R| 
     |I| = |0.595  -0.276  -0.333| * |G| 
     |Q|   |0.209  -0.522   0.287|   |B|  

  'argyb'
     |A |   |0.30   0.59   0.11|   |R|
     |Rg| = |0.50  -0.50   0.00| * |G|
     |Yb|   |0.25   0.25  -0.50|   |B|

  'ciexyz'
     |X|   |0.476   0.299   0.175|   |R|
     |Y| = |0.262   0.656   0.082| * |G|
     |Z|   |0.020   0.161   0.909|   |B| 

  '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)
        fi
        if (R == max)
           H = ((G - B) / (max - min)) * 60
        elif (G == max)
           H = (2 + (B - R) / (max - min)) * 60
        elif (B == max)
           H = (4 + (R - G) / (max - min)) * 60
        fi
     fi

  'hsi'
     |M1|   |2/Sqrt(6)  -1/Sqrt(6)  -1/Sqrt(6)|   |R|
     |M2| = |0           1/Sqrt(2)  -1/Sqrt(2)| * |G|
     |I1|   |1/Sqrt(3)   1/Sqrt(3)   1/Sqrt(3)|   |B|
     H = ATan(M1/M2)
     S = Sqrt(Sqr(M1) + Sqr(M2))
     I = I1 * Sqrt(3)                                           

  '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)) * 60
        elif (G == max)
           H = (2 + (B - R) / (max - min)) * 60
        elif (B == max)
           H = (4 + (R - G) / (max - min)) * 60
        fi
     fi

  '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
           A = (R + R - G - B) / 2
           B = (R - G) * (R - G) + (R - B) * (G - B)
           C = sqrt(B)
           if (C == 0)
              H = 0
           else
              H = acos(A / C)
           fi
           if (B > G)
              H = 2 * pi - H
           fi
        fi
     fi

  'isfeuklid'
     min = min(R,G,B)
     max = max(R,G,B)
     I = sqrt(R * R + G * G + B * B) / sqrt(3)
     if (I == 0)
        S = 0
        F = 0
     else
        S = acos(max(1, (R + G + B) / (I * 3))) / (pi / 2)
        if (R == min)
           F = acos(max(1, B / sqrt(G * G + B * B))) / (pi * 3 / 2) + 1 / 3
        elif (G == min)
           F = acos(max(1, R / sqrt(B * B + R * R))) / (pi * 3 / 2) + 2 / 3
        else
           F = acos(max(1, G / sqrt(R * R + G * G))) / (pi * 3 / 2)
        fi
     fi

  'isfdiff'
     if (R >= B && B >= G)
        I = R
        S = R - G
        F = (R - B) / 6
     elif (R >= G && G >= B)
        I = R
        S = R - B
        F = (2 - (R - G)) / 6
     elif (G >= R && R >= B)
        I = G
        S = G - B
        F = (2 + (G - R)) / 6
     elif (G >= B && B >= R)
        I = G
        S = G - R
        F = (4 - (G - B)) / 6
     elif (B >= G && G >= R)
        I = B
        S = B - R
        F = (4 + (B - G)) / 6
     else
        I = B
        S = B - G
        F = (6 + (B - R)) / 6
     fi

 'cielab'
     |X|   |0.476   0.299   0.175|   |R|
     |Y| = |0.262   0.656   0.082| * |G|
     |Z|   |0.020   0.161   0.909|   |B| 

     L = 116 * (Y ^ (1 / 3)) - 16
     a = 500 * (((X / 0.95) ^ (1 / 3)) - (Y ^ (1 / 3)))
     b = 200 * ((Y ^ (1 / 3)) - ((Z / 1.09) ^ (1 / 3)))

 'i1i2i3'
     |I1|   | 0.333 0.333 0.333|   |R|
     |I2| = | 1.0   0.0  -1.0  | * |G|
     |I3|   |-0.5   1.0  -0.5  |   |B|

 'ciexyz2'
     |X|   |0.620   0.170   0.180|   |R|
     |Y| = |0.310   0.590   0.110| * |G|
     |Z|   |0.000   0.066   1.020|   |B|

 'ciexyz3'
     |X|   |0.618   0.177   0.205|   |R|
     |Y| = |0.299   0.587   0.114| * |G|
     |Z|   |0.000   0.056   0.944|   |B|
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

ImageRed (input_object)
image(-array) -> Hobject: HImage(Array) ( byte / int1 / int2 / int4 / real / complex )
Input image (red channel).

ImageGreen (input_object)
image(-array) -> Hobject: HImage(Array) ( byte / int1 / int2 / int4 / real / complex )
Input image (green channel).

ImageBlue (input_object)
image(-array) -> Hobject: HImage(Array) ( byte / int1 / int2 / int4 / real / complex )
Input image (blue channel).

ImageResult1 (output_object)
image(-array) -> Hobject * : HImage(Array) ( byte / int1 / int2 / int4 / real / complex )
Color-transformed output image (channel 1).

ImageResult2 (output_object)
image(-array) -> Hobject * : HImage(Array) ( byte / int1 / int2 / int4 / real / complex )
Color-transformed output image (channel 1).

ImageResult3 (output_object)
image(-array) -> Hobject * : HImage(Array) ( byte / int1 / int2 / int4 / real / complex )
Color-transformed output image (channel 1).

ColorSpace (input_control)
string -> HTuple.char *
Color space of the output image.
Default value: 'hsv'
List of values: 'cielab', 'hsv', 'hsi', 'yiq', 'argyb', 'ciexyz', 'ciexyz2', 'ciexyz3', 'hls', 'ihs', 'isfeuklid', 'isfdiff', 'i1i2i3'


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_from_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


Alternatives

::rgb1_to_gray, ::rgb3_to_gray


See also

::trans_to_rgb


Module

Image filters



Copyright © 1996-2002 MVTec Software GmbH