File Exchange

image thumbnail

HSY <-> RGB Image Conversion Tools

version 2.0.0 (1.79 MB) by DGM
Convert images between RGB and HSY, a polar variant of YPbPr with normalized and bounded chroma.


Updated 19 Oct 2020

View Version History

View License

RGB2HSY() and HSY2RGB() can be used for conversion between sRGB and my own version of HSY. This method uses a polar adaptation of YPbPr wherein the chroma is normalized and bounded by the extent of the RGB cube (a subset of the entire YPbPr space). Like HuSL, this minimizes the occurrence and severity of clipping distortion. A point near the surface of the RGB cube will follow a noncircular path in the PbPr plane with hue rotation and a nonvertical path with Y scaling. Dramatic oversaturation merely pushes the point radially to the boundary of the RGB cube. In an unbounded method such as YPbPr or LCH, the point would be pushed far outside the sRGB gamut and then when clipping occurs on return to RGB, it would be remapped to some point distant from its exit.
The utility offered by this unconventional method is essentially the same as the HuSL method. H or S adjustments have very little effect on Y (see thumbnail). Extreme oversaturation has limited effect, unlike an unbounded LCH method. Compared to HuSL, both conversion and normalization tasks are simpler, resulting in an effective method with about 3x the speed of HuSL.
As with HuSL and HuSLp, the HSYp variant is normalized and bounded to the maximum biconic subset of the projected RGB space. This means HSYp 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). HSYp is mostly useful for relative specification of uniform colors. Compared to HuSLp, HSYp has access to a greater fraction of its parent space, making it a bit more flexible for tasks where uniformity is less important than color discrimination (e.g. specifying plot colormaps)
It's worth noting as well that in the output, H in HSY is aligned to the red corner of the RGB cube instead of to the PbPr plane. There would otherwise be a 108.6 degree offset between H in HSY and H in other models.
Output in the HSY format is of type double, in the range:
Documentation with commentary, example code, and input/output images is available here:
HuSL and HuSLp methods based on CIELAB and CIELUV are available here:
These tools are merely a subset of the Matlab Image Manipulation Toolbox (FEX)

Cite As

DGM (2020). HSY <-> 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

Community Treasure Hunt

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

Start Hunting!