File Exchange

image thumbnail

HuSL <-> RGB Image Conversion Tools

version 2.9.0.0 (4.79 MB) by DGM
Convert images between RGB and 'Human-Friendly HSL' (HuSL), a chroma-normalized variant of LAB/LUV

5 Downloads

Updated 19 Oct 2020

View Version History

View License

RGB2HUSL() and HUSL2RGB() can be used for conversion between sRGB and "Human-Friendly HSL" (HuSL). 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.
.
The direct LUV method is a fairly simple adaptation of the C and Lua implementations by Alexei Boronine et al:
https://www.hsluv.org/math/
.
See the thumbnail image for an example of hue rotation using various methods including HuSL.
Documentation with commentary, example code, and input/output images is available here:
http://myplace.frontier.com/~chooks9592/manual/html/imtweak.html
http://myplace.frontier.com/~chooks9592/manual/html/rgb2husl.html
.
For more information on the limitations of the LAB chroma bounding method, see:
http://epicbeardquest.blogspot.com/2015/11/the-problem-with-finding-boundary.html
.
For a faster alternative, these RGB<->HSY tools can be used for a similar result:
http://www.mathworks.com/matlabcentral/fileexchange/53572-hsy-%3C-%3E-rgb-image-conversion-tools
.
These tools are merely a subset of the Matlab Image Manipulation Toolbox (FEX)
https://www.mathworks.com/matlabcentral/fileexchange/53786-image-manipulation-toolbox

Cite As

DGM (2020). HuSL <-> RGB Image Conversion Tools (https://www.mathworks.com/matlabcentral/fileexchange/53423-husl-rgb-image-conversion-tools), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Colorspace Transformations

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

huslconversions

huslconversions/lchconversions