Updated 14 Jan 2011
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 Matlab, colorspace is compiled as a MEX function by entering
on the Matlab command console. As an alternative to MEX, a pure M-code version colorspace.m is also included.
For use in C programs, an example command line program colorcalc is included.
B = colorspace(S,A) converts the color representation of image A where S is a string specifying the conversion. S tells the source and destination color spaces, S = 'dest<-src', or alternatively, S = 'src->dest'. Supported color spaces are
'RGB' = sRGB IEC 61966-2-1
'YPbPr' = Luma (ITU-R BT.601) + Chroma
'YCbCr' = Luma + Chroma
'JPEG-YCbCr' = space used in 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'.
Pascal Getreuer (2023). Colorspace Transformations (https://www.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
- Image Processing and Computer Vision > Image Processing Toolbox > Import, Export, and Conversion >
- Image Processing and Computer Vision > Image Processing Toolbox > Image Segmentation and Analysis > Image Segmentation > L*a*b* Color Space >
Inspired: hslcolormap, colormapgen, cbrewer2, Perceptually improved colormaps, Generate maximally perceptually-distinct colors, Explore Experimental Data
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
added tags, minor update in documentation
* Added missing colorspace.h file---thanks to William Cook