trans_from_rgb ( ImageRed, ImageGreen, ImageBlue : ImageResult1, ImageResult2, ImageResult3 : ColorSpace : )

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|  

  'yuv'
     |Y|   | 0.299   0.587   0.114|   |R| 
     |U| = |-0.147  -0.289   0.436| * |G| 
     |V|   | 0.615  -0.515   0.100|   |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| 

     Used primary colors (x,y,z):
       red:=(0.628,0.346,0.026), green:=(0.268,0.588,0.144), 
       blue:=(0.150,0.070,0.780), white65:=(0.313,0.329,0.358)

     Range of values:
       X:=[0;0.951], Y:=[0;1], Z:=[0;1.088]


  '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(M2/M1)
     S = Sqrt(M1*M1 + M2*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

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

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

     |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 * f(Y/Yw) - 16
     a = 500 * (f(X/Xw) - f(Y/Yw))
     b = 200 * (f(Y/Yw) - f(Z/Zw))
     
     where 
       f(t) = t^(1/3),           t > 0.008856
       f(t) = 7.787*t + 16/116,  else.

     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)

     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 will be scaled to 
	  maximum or minimum gray value, respectively)

 '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 one of the following conditions is fulfilled, certain scalings are performed accordingly to the image type:
  - Considering byte images, the domain of color space values is generally
    mapped to the full domain of [0..255]. The origin of signed values is
    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

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

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

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

ImageResult1 (output_object)
image(-array) -> object : byte / int4 / real
Color-transformed output image (channel 1).

ImageResult2 (output_object)
image(-array) -> object : byte / int4 / real
Color-transformed output image (channel 1).

ImageResult3 (output_object)
image(-array) -> object : byte / int4 / real
Color-transformed output image (channel 1).

ColorSpace (input_control)
string -> string
Color space of the output image.
Default value: 'hsv'
List of values: 'cielab_new', 'hsv', 'hsi', 'yiq', 'yuv', 'argyb', 'ciexyz', 'ciexyz2', 'ciexyz3', 'hls', 'ihs', '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 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_from_rgb is reentrant and automatically parallelized (on tuple level, domain level).


Possible Predecessors

decompose3


Possible Successors

compose3


Alternatives

rgb1_to_gray, rgb3_to_gray


See also

trans_to_rgb


Module

Foundation



Copyright © 1996-2008 MVTec Software GmbH