File Exchange

image thumbnail

HuSL <-> RGB Image Conversion Tools

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

0 Downloads

Updated 24 Jul 2016

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.
.
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:
http://www.husl-colors.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

Comments and Ratings (0)

Updates

2.8.0.0

added range enforcement to prevent LUT seek errors
bugfix in maxchroma for unrelated YPbPr case

2.7.0.0

removed IPT dependency

2.6.0.0

reduced package size

2.5.0.0

fixed botched update

2.5.0.0

updated LCH conversion tools

2.5.0.0

updated docs links

2.5.0.0

code cleanup of sRGB-LCH functions for accuracy and possible extensibility

2.4.1.0

bugfix in maxchroma(), fixes convergence problems in 'labcalc' mode

2.4.0.0

fixed LAB chroma bounding inaccuracy at yellow corner
it's still a numeric method, but it returns correct results at the apex

2.3.0.0

offloaded bounding chroma calculations to a separate function and added a tentative direct calculation method for LAB
recalculated LUT for LCHab with better accuracy near yellow corner

2.2.0.0

added HuSLn (native) modes
updated LCH conversion functions

2.1.0.0

fixed urls

2.1.0.0

added HuSLp methods for both CIELAB and CIELUV

2.0.0.0

fixed zip file

2.0.0.0

updated a file

1.0.0.0

Added CIELCHab method and implemented LUT use.
Provided a custom RGB<->LCH tool set to avoid truncation issues

1.0.0.0

uploaded the wrong example picture

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

Inspired by: Colorspace Transformations