Skip to content

linear_trans_colorLinearTransColorLinearTransColorlinear_trans_colorT_linear_trans_color🔗

Short description🔗

linear_trans_colorLinearTransColorLinearTransColorlinear_trans_colorT_linear_trans_color — Compute an affine transformation of the color values of a multichannel image.

Signature🔗

linear_trans_color( image Image, out image ImageTrans, real TransMat )void LinearTransColor( const HObject& Image, HObject* ImageTrans, const HTuple& TransMat )static void HOperatorSet.LinearTransColor( HObject image, out HObject imageTrans, HTuple transMat )def linear_trans_color( image: HObject, trans_mat: Sequence[float] ) -> HObject

Herror T_linear_trans_color( const Hobject Image, Hobject* ImageTrans, const Htuple TransMat )

HImage HImage::LinearTransColor( const HTuple& TransMat ) const

HImage HImage.LinearTransColor( HTuple transMat )

Description🔗

linear_trans_colorLinearTransColor performs an affine transformation of the color values of the multichannel image Imageimageimage and returns the result in ImageTransimageTransimage_trans. The affine transformation of the color values is described by the transformation matrix TransMattransMattrans_mat. If \(n\) is the number of channels in Imageimageimage and \(m\) is the number of channels in ImageTransimageTransimage_trans, TransMattransMattrans_mat is a homogeneous m × (n+1) matrix that is stored row by row. Homogeneous means that the left m × n submatrix of TransMattransMattrans_mat describes a linear transformation of the color values, while the last column of TransMattransMattrans_mat describes a constant offset of the color values. The transformation matrix is typically computed with gen_principal_comp_transGenPrincipalCompTrans. In particular, it is possible to project an image onto the first \(m\) principal components by selecting the first m × (n+1) values of the transformation returned by gen_principal_comp_transGenPrincipalCompTrans. The transformation can, however, also be specified directly. For example, a transformation from RGB to YIQ, which is described by the following transformation

\[\begin{eqnarray*} \left( \begin{array}{c} Y \\ I \\ Q \end{array} \right) = \left( \begin{array}{rrr} 0.299 & 0.587 & 0.114 \\ 0.599 & -0.276 & -0.324 \\ 0.214 & -0.522 & 0.309 \end{array} \right) \left( \begin{array}{c} R \\ G \\ B \end{array} \right) + \left( \begin{array}{c} 0 \\ 127.5 \\ 127.5 \end{array} \right) \end{eqnarray*}\]

can be achieved by setting TransMattransMattrans_mat to [0.299,0.587,0.114,0.0,0.599,-0.276,-0.324,127.5,0.214,-0.522,0.309,127.5] Here, it should be noted that the above transformation is unnormalized, i.e., the resulting color values can lie outside the range \([0,255]\). The transformation 'yiq'"yiq" in trans_from_rgbTransFromRgb additionally scales the rows of the matrix (except for the constant offset) appropriately.

To avoid a loss of information, linear_trans_colorLinearTransColor returns an image of type real. If a different image type is desired, the image can be transformed with convert_image_typeConvertImageType.

Attention🔗

linear_trans_colorLinearTransColor can be executed on OpenCL devices if the image Imageimageimage consists of nine channels or less and is transformed to an image of three channels or less. Since the calculations are done in single precision floating point, the results may differ from those calculated by the CPU.

Execution information🔗

Execution information
  • Supports OpenCL compute devices.

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on tuple level.

  • Automatically parallelized on domain level.

Parameters🔗

Imageimageimage (input_object) multichannel-image(-array) → object (byte / direction / cyclic / int1 / int2 / uint2 / int4 / real)HObject (byte / direction / cyclic / int1 / int2 / uint2 / int4 / real)HImage (byte / direction / cyclic / int1 / int2 / uint2 / int4 / real)HObject (byte / direction / cyclic / int1 / int2 / uint2 / int4 / real)Hobject (byte / direction / cyclic / int1 / int2 / uint2 / int4 / real)

Multichannel input image.

ImageTransimageTransimage_trans (output_object) multichannel-image(-array) → object (real)HObject (real)HImage (real)HObject (real)Hobject * (real)

Multichannel output image.

TransMattransMattrans_mat (input_control) real-array → (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Transformation matrix for the color values.

Result🔗

The operator linear_trans_colorLinearTransColor returns the value 2 (H_MSG_TRUE) if the parameters are correct. Otherwise an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

gen_principal_comp_transGenPrincipalCompTrans

Possible successors

convert_image_typeConvertImageType

Alternatives

principal_compPrincipalComp, trans_from_rgbTransFromRgb, trans_to_rgbTransToRgb

Module🔗

Foundation