Colorspace Conversion Tools

Version 2.7 (5.83 MB) by DGM
Image conversion tools from MIMT
1.6K Downloads
Updated 4 Jul 2024
This package includes bidirectional tools for converting between sRGB and the following color models:
HSI
HSL
HWB
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)
Various luma-chroma models (YPbPr, YCbCr, YUV, YIQ, YDbDr, YCoCg)
CMYK (a naive transformation for the purpose of changing from additive to subtractive workflow -- not a profiled method for print)
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:

Cite As

DGM (2024). Colorspace Conversion Tools (https://github.com/291ce4321ac/MIMT-conversion-tools/releases/tag/v2.7), GitHub. Retrieved .

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

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
2.7

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-conversion-tools/releases/tag/v2.7

2.6

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-conversion-tools/releases/tag/v2.6

2.5.0.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-conversion-tools/releases/tag/v2.5

2.4.2.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-conversion-tools/releases/tag/v2.4.2

2.4.1.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-conversion-tools/releases/tag/v2.4.1

2.4.0.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-conversion-tools/releases/tag/v2.4

2.3.2

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-conversion-tools/releases/tag/v2.3.2

2.3.1

minor update to a support file

2.3

added clones of GMIC's naive RGB-CMYK tools for sake of supporting demos of some GMIC code in the main toolbox

2.2

added HWB tools
added polar/rect conversion tools
added YCoCg to gettfm()

2.1.1

minor support file update

2.1.0.1

description edit

2.1

added OKLAB support
split out sRGB <-> linear RGB conversion tools
code cleanup gives speed boost for most modes
maxchroma srlab calc had a logic bug that messed up convergence on yellow corner
improved maxchroma srlab LUT lookup routine

2.0.1

improved synopsis citation for SRLAB2
original site and pdf are long gone, but added paper title and author

2.0

migrating all the other CS conversion tools over here so that they're in one place
i hate having to deal with updating all the packages individually

1.2.0.0

minor dependency update

1.1.0.0

removed IPT dependency

1.0.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.