HALCON Reference Manual 10.0.2
Table of Contents / Filters / Color ClassesClassesClasses | | | Operators

trans_from_rgbtrans_from_rgbtrans_from_rgbTransFromRgbTransFromRgb (Operator)

Name

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

Signature

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

Herror trans_from_rgb(const Hobject ImageRed, const Hobject ImageGreen, const Hobject ImageBlue, Hobject* ImageResult1, Hobject* ImageResult2, Hobject* ImageResult3, const char* ColorSpace)

Herror T_trans_from_rgb(const Hobject ImageRed, const Hobject ImageGreen, const Hobject ImageBlue, Hobject* ImageResult1, Hobject* ImageResult2, Hobject* ImageResult3, const Htuple ColorSpace)

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

HImage HImage::TransFromRgb(const HImage& ImageGreen, const HImage& 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

void HOperatorSetX.TransFromRgb(
[in] IHUntypedObjectX* ImageRed, [in] IHUntypedObjectX* ImageGreen, [in] IHUntypedObjectX* ImageBlue, [out] IHUntypedObjectX*ImageResult1, [out] IHUntypedObjectX*ImageResult2, [out] IHUntypedObjectX*ImageResult3, [in] VARIANT ColorSpace)

IHImageX* HImageX.TransFromRgb(
[in] IHImageX* ImageGreen, [in] IHImageX* ImageBlue, [out] IHImageX*ImageResult2, [out] IHImageX*ImageResult3, [in] BSTR ColorSpace)

static void HOperatorSet.TransFromRgb(HObject imageRed, HObject imageGreen, HObject imageBlue, out HObject imageResult1, out HObject imageResult2, out HObject imageResult3, HTuple colorSpace)

HImage HImage.TransFromRgb(HImage imageGreen, HImage imageBlue, out HImage imageResult2, out HImage imageResult3, string colorSpace)

Description

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

The operator trans_from_rgbtrans_from_rgbtrans_from_rgbTransFromRgbTransFromRgb supports the image types byte, uint2, int4, and real. In the case of int4 images, the images should not contain negative values. In the case of real images, all values should lay within 0 and 1. If not, the results of the transformation may not be reasonable.

Certain scalings are performed accordingly to the image type:

The following transformations are supported:

(All range of values are based on RGB values scaled to [0;1]. To obtain the range of values for a certain image type, they must be multiplied with the maximum of the image type, e.g., 255 in the case of a byte image)

'yiq'

  |Y|   |0.299   0.587   0.114|   |R|
  |I| = |0.599  -0.276  -0.324| * |G|
  |Q|   |0.214  -0.522   0.309|   |B|

Range of values:

Y = [0;1], I = [-0.599;0.599], Q = [-0.522;0.522]

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

Range of values:

Y = [0;1], U = [-0.436;0.436], V = [-0.615;0.615]

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

Range of values:

A = [0;1], Rg = [-0.5,0.5], Yb = [-0.5, 0.5]

'ciexyz'

     |X|   |0.412453  0.357580  0.180423|   |R|
     |Y| = |0.212671  0.715160  0.072169| * |G|
     |Z|   |0.019334  0.119193  0.950227|   |B|

The primary colors used correspond to sRGB respectively CIE Rec. 709. D65 is used as white point.

Used primary colors (x,y,z):

         x         y
  red    0.6400    0.3300
  green  0.3000    0.6000
  blue   0.1500    0.0600
  white  0.3127    0.3290

Range of values:

X:=[0;0.950456], Y:=[0;1], Z:=[0;1.088754]

'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

Range of values:

H = [0;2pi], L = [0;1], S = [0;1]

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

Range of values:

H = [0;2pi], S= [0;Sqrt(2/3)], I = [0;1]

'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

Range of values:

H = [0;2pi], S = [0;1], V = [0;1]

'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
 

Range of values:

I = [0;1], H = [0;2pi], S = [0;1]

'cielab'

  |X|   |0.412453  0.357580  0.180423|   |R|
  |Y| = |0.212671  0.715160  0.072169| * |G|
  |Z|   |0.019334  0.119193  0.950227|   |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 > (24/116)^3
     f(t) = (841/108)*t + 16/116,  otherwise.

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

Range of values:

L := [0; 100], a := [-86.1813; 98.2352], b := [-107.8617;94.4758] (Scaled to the maximum gray value in the case of byte and uint2. In the case of int4 L and a are scaled to the maximum gray value, b is scaled to the minimum gray value, such that the origin stays at 0.)

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

Range of values:

I1 = [0;1], I2 = [-1;1], I3 = [-1;1]

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

Range of values:

X = [0;0.970], Y = [0;1.010], Z = [0;1.086]

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

Range of values:

X = [0;1], Y = [0;1], Z = [0;1]

'ciexyz4'

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

  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]

Attention

As the calculations are made with a different numerical precision, the OpenCL implementation of the cielab transformation for images of type int4 is slightly less accurate than the pure C version.

Parallelization

Parameters

ImageRedImageRedImageRedImageRedimageRed (input_object)  image(-array) objectHImageHImageHImageXHobject (byte / uint2 / int4 / real)

Input image (red channel).

ImageGreenImageGreenImageGreenImageGreenimageGreen (input_object)  image(-array) objectHImageHImageHImageXHobject (byte / uint2 / int4 / real)

Input image (green channel).

ImageBlueImageBlueImageBlueImageBlueimageBlue (input_object)  image(-array) objectHImageHImageHImageXHobject (byte / uint2 / int4 / real)

Input image (blue channel).

ImageResult1ImageResult1ImageResult1ImageResult1imageResult1 (output_object)  image(-array) objectHImageHImageHImageXHobject * (byte / uint2 / int4 / real)

Color-transformed output image (channel 1).

ImageResult2ImageResult2ImageResult2ImageResult2imageResult2 (output_object)  image(-array) objectHImageHImageHImageXHobject * (byte / uint2 / int4 / real)

Color-transformed output image (channel 1).

ImageResult3ImageResult3ImageResult3ImageResult3imageResult3 (output_object)  image(-array) objectHImageHImageHImageXHobject * (byte / uint2 / int4 / real)

Color-transformed output image (channel 1).

ColorSpaceColorSpaceColorSpaceColorSpacecolorSpace (input_control)  string HTupleHTupleVARIANTHtuple (string) (string) (char*) (BSTR) (char*)

Color space of the output image.

Default value: 'hsv' "hsv" "hsv" "hsv" "hsv"

List of values: 'cielab'"cielab""cielab""cielab""cielab", 'hsv'"hsv""hsv""hsv""hsv", 'hsi'"hsi""hsi""hsi""hsi", 'yiq'"yiq""yiq""yiq""yiq", 'yuv'"yuv""yuv""yuv""yuv", 'argyb'"argyb""argyb""argyb""argyb", 'ciexyz'"ciexyz""ciexyz""ciexyz""ciexyz", 'ciexyz2'"ciexyz2""ciexyz2""ciexyz2""ciexyz2", 'ciexyz3'"ciexyz3""ciexyz3""ciexyz3""ciexyz3", 'ciexyz4'"ciexyz4""ciexyz4""ciexyz4""ciexyz4", 'hls'"hls""hls""hls""hls", 'ihs'"ihs""ihs""ihs""ihs", 'i1i2i3'"i1i2i3""i1i2i3""i1i2i3""i1i2i3"

List of values (for compute devices): 'cielab'"cielab""cielab""cielab""cielab", 'hsv'"hsv""hsv""hsv""hsv", 'hsi'"hsi""hsi""hsi""hsi"

Example (HDevelop)

* Transformation 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)

Example (C)

/* Transformation 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);

Example (HDevelop)

* Transformation 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)

Example (HDevelop)

* Transformation 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)

Example (HDevelop)

* Transformation 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_rgbtrans_from_rgbtrans_from_rgbTransFromRgbTransFromRgb 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>:)set_system("no_object_result",<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>). If necessary, an exception is raised.

Possible Predecessors

decompose3decompose3decompose3Decompose3Decompose3

Possible Successors

compose3compose3compose3Compose3Compose3

Alternatives

linear_trans_colorlinear_trans_colorlinear_trans_colorLinearTransColorLinearTransColor, rgb1_to_grayrgb1_to_grayrgb1_to_grayRgb1ToGrayRgb1ToGray, rgb3_to_grayrgb3_to_grayrgb3_to_grayRgb3ToGrayRgb3ToGray

See also

trans_to_rgbtrans_to_rgbtrans_to_rgbTransToRgbTransToRgb

References

ITU-R BT.470-6: “Conventional Television Systems”, 1998.

Module

Foundation


Table of Contents / Filters / Color ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH