File Exchange

image thumbnail

HSY <-> RGB Image Conversion Tools

version 1.4.1.0 (6.33 KB) by DGM
Convert images between RGB and HSY, a polar variant of YPbPr with normalized and bounded chroma.

1 Download

Updated 11 May 2018

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:
0<H<360
0<S<1
0<Y<1
.
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/rgb2hsy.html
.
HuSL and HuSLp methods based on CIELAB and CIELUV are available here:
http://www.mathworks.com/matlabcentral/fileexchange/53423-husl-%3C-%3E-rgb-image-conversion-tools

Comments and Ratings (0)

Updates

1.4.1.0

safeguard against cases where hue values are NaN

1.4.0.0

changed range enforcement behavior in hsy2rgb

1.3.0.0

removed IPT dependency

1.2.0.0

updated docs links

1.2.0.0

added a 'native' mode option

1.1.0.0

fixed archive

1.1.0.0

added rotationally-symmetric variant methods (HSYp)

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