Hue, saturation and value adjustment¶
| Fact | Value |
|---|---|
| Also called | HSV adjustment, Hue/Saturation |
| Status | Implemented and tested |
| Family | Enhancement, illumination and color |
| Engine | Browser |
| Type | Nonlinear, color, HSV adjustment |
| Output | Image |
| Operator shown as | color-transform (exact) |
| Support radius | 0 |
| Code | web/src/core/filters/enhancement/color-adjust.ts, hsvAdjustFilter |
| Operator code | web/src/core/filters/enhancement/color-adjust.ts, hsvAdjustFilter |
Overview¶
This filter changes colors in the HSV model of Smith. It turns the hue by an angle, and scales the saturation and the value. These three controls match how people describe color: which color, how strong and how bright.
How it works¶
- Convert each pixel to hue, saturation and value.
- Add the hue shift, and scale the saturation and the value, capped at 1.
- Convert back to red, green and blue.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(H, S, V\): Hue in degrees, saturation and value from 0 to 1
- \(\Delta H\): The hue shift
- \(f_S, f_V\): The saturation and value factors
HSV is the hexcone model of Smith. V is the largest channel, S = (max - min) / max, and H is the angle around the color wheel. The hue shift wraps around at 360 degrees. Saturation and value are scaled and capped at 1, so no channel leaves the range. The conversion works on the encoded sRGB values.
In the hexcone model, V is the largest channel, S = (max - min) / max, and H is the position around a hexagon of the six primary and secondary colors. A hue shift moves a color around the hexagon at the same S and V. Unlike hue rotation, it turns the HSV hue by exactly the angle, but it does not keep the gray value.
Kernel or operator¶
The Inspector shows the three steps with the current shift and factors.
Algorithm¶
- Convert the pixel to HSV.
- Add the hue shift, and scale the saturation and the value, capped at 1.
- Convert back to RGB.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Hue hue |
0 | -180 to 180 deg | The angle added to the hue. |
Saturation saturation |
130 | 0 to 300 % | The factor for the HSV saturation, in percent. |
Value value |
100 | 0 to 300 % | The factor for the HSV value, the largest channel, in percent. |
Implementation¶
hsvAdjustFilter in web/src/core/filters/enhancement/color-adjust.ts uses rgbToHsv and hsvToRgb from web/src/core/color/convert.ts. It is a pixel filter: the runner calls it once per pixel with the red, green and blue values, and rounds and clips the results at the end.
Worked example¶
| Input | Settings | Output | Pixel |
|---|---|---|---|
| (200, 100, 50) | hue + 120 | (50, 200, 100) | (50, 200, 100) |
| (200, 100, 50) | saturation 50 | (200, 150, 125) | (200, 150, 125) |
| (200, 100, 50) | value 150 | (255, 127.5, 63.8) | (255, 127, 64) |
The input has hue 20 degrees, saturation 0.75 and value 200 / 255 = 0.78. A hue shift of 120 degrees gives hue 140, a green, with the same saturation and value. Value 150 percent would give 1.18, so it is capped at 1 and the largest channel becomes 255.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(1)\)
N is the number of pixels. Each pixel takes a fixed number of operations.
Artifacts and limitations¶
Limitations
- HSV value is not perceived brightness. A hue shift can change how bright a color looks.
- Capping at 1 flattens strong colors when the factors are high.
Artifacts
- Hue jumps in noisy, nearly gray areas, where the hue is unstable.
Tests¶
The reference computes the same steps with Python's colorsys module, an independent HSV code with NumPy on a small RGB test image with saturated, gray, black and white pixels. Each case compares all three channels.
References¶
- Smith, A. R. Color gamut transform pairs. ACM SIGGRAPH Computer Graphics 12(3), 12 to 19, 1978. DOI 10.1145/965139.807361.
- GIMP documentation, the Hue-Saturation tool. https://docs.gimp.org/2.10/en/gimp-tool-hue-saturation.html