This package includes bidirectional tools for converting between sRGB and the following color models:
HSY (chroma-normalized polar YPbPr)
HuSL (chroma-normalized LCHab and LCHuv)
HSYp (rotationally-symmetric subset of HSY)
HuSLp (rotationally-symmetric subset of HuSL)
LCH (polar variants of LAB, LUV, OKLAB, and SRLAB)
Also included is maxchroma(), a tool used for finding the maximum chroma of the sRGB gamut given L & H coordinates in any of the supported spaces (LCHab, LCHuv, SRLAB2 LCH, as well as polar YPbPr and biconic subsets of these spaces)
▒▒ HSI and HSL:
These really need no introduction. The included tools are basic and provide conventional functionality.
▒▒ HuSL and HSY:
HuSL and HSY are merely conceptually similar adaptations of different families of color models. "Human-Friendly HSL" (HuSL) is a chroma-normalized variant of CIELCH designed to keep operations within the sRGB gamut. This is convenient for intuitive selection of colors, or for color adjustment with the intention of returning to RGB space. While the original HuSL developer has changed the model name from HuSL to HSLuv, these tools still use the original naming conventions.
As L and H are varied in LCH, the maximum allowable chroma changes dramatically and nonintuitively. Increasing L or rotating H for a highly saturated color will often move the color point outside the RGB gamut and cause undesired results.
While HuSL has convenience or particular advantages over LCH, it's slower and has a highly distorted chroma space. This makes it less useful for direct color comparison or specification. HuSLp variants are normalized and bounded to the maximal biconic subset of the projected RGB space. This means HuSLp avoids distortion of the chroma space when normalizing, preserving the uniformity of the parent space. Unfortunately, this also means it can only render colors near the neutral axis (pastels). HuSLp is mostly useful for relative specification of uniform colors.
The original HuSL implementations are all based on CIELCHuv. This version offers the option to use either CIELCHab or CIELCHuv. By default, lookup tables are used for speed, though a direct calculation method can be optionally specified.
▒▒ LCH tools:
The core functions RGB2LCH and LCH2RGB have several optional modes not found in other conversion tools. These include the following ...
The ability to control data truncation behavior: LCH data may be truncated before or after converting to RGB. Conventional conversion tools truncate after conversion, resulting in out-of-gamut points being compressed toward the saturated corners of the RGB cube. Truncation before conversion minimizes apparent image alteration, and may be achieved via a LUT for speed, or via direct calculation if desired. The user may also opt to not truncate data at all (default).
For the purpose of testing in-gamut state, the gamma-correction routine can be optionally disabled. This speeds calculations when finding the gamut boundaries.
Support for 65k white point (standard for sRGB), and a Bradford-adapted conversion for a 50k white point is also available.
Information on SRLAB2 can be found at http://www.magnetkern.de/srlab2.html
Information on OKLAB can be found at https://bottosson.github.io/posts/oklab/
The direct LUV method for HuSL is a fairly simple adaptation of the C and Lua implementations by Alexei Boronine et al:
These files are part of my Matlab Image Manipulation Toolbox:
DGM (2022). Colorspace Conversion Tools (https://www.mathworks.com/matlabcentral/fileexchange/53354-colorspace-conversion-tools), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Inspired by: Colorspace Transformations
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!