convert a color image from a given color space to another
This algorithm allows to convert an input color image from its color space (the sourceColorSpace) to another color space defined by InColorConversionTransform (the targetColorSpace)
IPSDK will select the algorithm to use in function of the color space of the input image attribute InColorImg and of TargetColorSpace value of parameter InColorConversionTransform.
Details of used transformations can be found at Color models.
In some cases, a linear transform allows to transform a color space to another with following equation :
where :
and
are color plan indexes
is equal to number of color channels of input image
are components of matrix of underlying linear system
are components of vector of underlying linear system
This linear system can then be rewritten as follow :
where :
and
are respectively a
matrix and a
vector associated to underlying linear system
and
are color space vector respresentations of used images
This is the case when :
- ipsdk::image::hasLinearTransform(sourceColorSpace, targetColorSpace) returns true.
- sourceColorSpace or targetColorSpace is equal to ipsdk::image::eColorGeometryType::eCGT_User. In this case, LinearTransform value of parameter InColorConversionTransform will be used as linear transform.
In some other cases such as sourceColorSpace or targetColorSpace in :
- ipsdk::image::eColorGeometryType::eCGT_CieLab
- ipsdk::image::eColorGeometryType::eCGT_CieLuv
- ipsdk::image::eColorGeometryType::eCGT_HLS
- ipsdk::image::eColorGeometryType::eCGT_HSV
a specific algorithm is used to proceed to conversion.
- Note
- If the source color space is Cie Lab or Cie Luv and if a user linear transform is provided, then this linear transform should allow to go from CIE XYZ color space to the user color space. The transform from the Cie Lab/Cie Luv to the CIE XYZ color space will be automatically pre-proceeded.
-
If the target color space is Cie Lab or Cie Luv and if a user linear transform is provided, then this linear transform should allow to go from the user color space to the CIE XYZ color space. The transform from CIE XYZ color space to the Cie Lab/Cie Luv will be automatically post-proceeded.
-
For RGB to XYZ or RGB to Cie Lab conversions, we consider that the input color space is standard RGB (sRGB). Hence, to comply with this predicate, the input color image range must be [0, 255].
In the case where the output image is not provided, the output buffer type is set to :
- the input buffer type if proceeding an RGB<->RGBA conversion
- the input buffer type if targetColorSpace is equal to ipsdk::image::eColorGeometryType::eCGT_YCbCr
- ipsdk::image::eImageBufferType::eIBT_Real32 otherwise
- Warning
- If an output image is provided, be sure to use a suitable output image buffer type to avoid problems such as signed/unsigned conversion, buffers overflow or loss of precision. In such a case, the output value is undefined.
Rgb to YPbPr example
In this case, output image values are given by:
Here is an example of a YPbPr to Rgb color base conversion operation applied to a 8-bits image :
YPbPr to Rgb example
In this case, the output image values are given by:
Here is an example of a YPbPr to Rgb color base conversion operation applied to a 8-bits image :
- See also
- https://en.wikipedia.org/wiki/YCbCr
-
https://en.wikipedia.org/wiki/RGB_color_model
Example of Python code :
Example imports
import PyIPSDK
import PyIPSDK.IPSDKIPLColor as color
import PyIPSDK.IPSDKIPLUtility as util
Code Example
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
outImgYPbPr = color.colorConvertImg(inImg, PyIPSDK.eColorGeometryType.eCGT_YPbPr)
outImgLab = color.colorConvertImg(inImg, PyIPSDK.eColorGeometryType.eCGT_CieLab)
transMat = [0.5, 0.5, 0, -12,
0, 1, 0, 0,
0, 0, 1, 0]
outImgUser = color.colorConvertImg(inImg, PyIPSDK.createToUserColorConversionTransform(transMat))
Example of C++ code :
Example informations
Header file
#include <IPSDKIPL/IPSDKIPLColor/Processor/ColorConvertImg/ColorConvertImg.h>
Code Example
ImagePtr pOutColorImg = colorConvertImg(pInputColorImg, targetColorGeometryType);