Sciweavers

Share

Source Code

Colorspace Transformations

10 years 5 months ago
Colorspace Transformations
Transform colors between sRGB, YCbCr, YPbPr, YUV, YIQ, HSV, HSL, HSI, XYZ, Lab, Luv, LCH, CAT02 LMS
Added 29 Sep 2010
Updated 05 Sep 2011
Authors Pascal Getreuer
OS All OS
Language C
This package converts colors between sRGB, Y'PbPr, Y'CbCr, JPEG-Y'CbCr, Y'UV, Y'IQ, Y'DbDr, HSV, HSL, HSI, CIE XYZ, CIE L*a*b* (CIELAB), CIE L*u*v* (CIELUV), and CIE L*ch (CIELCH), and CIE CAT02 LMS. It can be used either as part of a C/C++ program or compiled as a Matlab MEX function.

For use in C programs, an example command line program colorcalc is included.  For use in Matlab, colorspace is compiled as a MEX function by entering

mex colorspace.c

on the Matlab command console. As an alternative to MEX, a pure M-code version colorspace.m is also included.

To perform a color transformation, first call GetColorTransform, specifying the source and destination color spaces as "dest<-src" or "src->dest". Then call ApplyColorTransform to perform the transform:

num S[3] = {173, 0.8, 0.5};
num D[3];
colortransform Trans;
       
if(!(GetColorTransform(&Trans, "HSI -> Lab")))
{
    printf("Invalid syntax or unknown color space\n");
    return;
}   
       
ApplyColorTransform(Trans, &D[0], &D[1], &D[2], S[0], S[1], S[2]);

num” is a typedef defined at the beginning of colorspace.h that may be set to either double or float, depending on the application.

The supported spaces are
"RGB"sRGB IEC 61966-2-1
"YPbPr"Luma (ITU-R BT.601) + Chroma
"YCbCr"Luma + Chroma (digitized version of Y'PbPr)
"JPEG-YCbCr"Luma + Chroma space used in JFIF JPEG
"YUV"NTSC PAL Y'UV Luma + Chroma
"YIQ"NTSC Y'IQ Luma + Chroma
"YDbDr"SECAM Luma + Chroma
"HSV" or "HSB" 
Hue Saturation Value/Brightness
"HSL" or "HLS"Hue Saturation Luminance
"HSI"Hue Saturation Intensity
"XYZ"CIE XYZ
"Lab"CIE L*a*b* (CIELAB)
"Luv"CIE L*u*v* (CIELUV)
"LCH"CIE L*C*H* (CIELCH)
"CAT02 LMS"CIE CAT02 LMS
All transforms assume 2 degree observer and D65 illuminant. Color space names are case insensitive. When sRGB is the source or destination, it can be omitted. For example "yuv<-" is short for "yuv<-rgb".

Similarly in Matlab, B = colorspace(S,A) converts the color representation of image A where S is a string with the format S = 'dest<-src' or S = 'src->dest' specifying the transformation.

This material is based upon work supported by the National Science Foundation under Award No. DMS-1004694. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Comments (0)
books