Color Range, brightness and hue selections¶
Color Range¶
| Fact | Value |
|---|---|
| Status | Implemented and tested |
| Group | Color and tone |
| Engine | Browser |
| Code | web/src/core/selection/range.ts, colorRange |
Select by brightness¶
| Fact | Value |
|---|---|
| Status | Implemented and tested |
| Group | Color and tone |
| Engine | Browser |
| Code | web/src/core/selection/range.ts, selectBrightness |
Select by hue and saturation¶
| Fact | Value |
|---|---|
| Status | Implemented and tested |
| Group | Color and tone |
| Engine | Browser |
| Code | web/src/core/selection/range.ts, selectHsv |
Overview¶
These three commands in the Select menu select by color or tone across the whole image, not only connected pixels. Unlike the Magic Wand, they give a soft selection: pixels a little outside the range are partly selected. Filters then fade out smoothly.
How to use them¶
Each command opens a dialog with its settings, a small preview and the share of the image it selects.
- Color Range: click the preview to sample a color. Shift-click adds a sample, Alt-click removes the nearest one. To sample with the keyboard, pin a pixel with the Probe tool (I) first, then press Add the Probe pixel. The Select list also has the shadows, midtones and highlights presets.
- Select by brightness: set the range of brightness, from 0 (black) to 255 (white).
- Select by hue and saturation: set the center hue and the ranges of saturation and value.
The buttons at the bottom of the settings say how the result combines with the current selection. Preview switches between the selection in gray and the image.
How it works¶
Color Range:
- For sampled colors, read the color of each sample.
- For each pixel, find the nearest sample in the chosen color space.
- Select it fully up to the tolerance, then fade the selection to 0 over the fuzziness.
- With localized colors, also fade by the distance in pixels from each sample.
- For a tone preset, weight each pixel by its BT.709 luma instead.
- Combine with the current selection by the mode chosen in the dialog.
Select by brightness:
- Compute the BT.709 luma of each pixel, from 0 to 255.
- Select it fully when it lies between From and To.
- Outside the range, fade the selection to 0 over the softness, in luma levels.
Select by hue and saturation:
- Convert each pixel to hue, saturation and value.
- Measure how far the hue is from the center hue, around the color circle.
- Measure how far saturation and value are outside their ranges.
- Fade each part to 0 over the softness, and take the smallest of the three.
Mathematical foundation¶
All three use the same soft ramp. For a distance \(d\), a full range \(F\) and a softness \(S\):
where
- \(d\) is a distance, in color or in brightness,
- \(F\) is the largest distance that is still fully selected,
- \(S\) is the distance over which the value falls from 1 to 0.
The mask value is \(255\,\rho\), rounded. This is an exact computation.
Color Range. With samples \(C_k\), the value at pixel \(p\) is \(\max_k \rho(\lVert C(p) - C_k \rVert; T, F)\), with \(T\) the tolerance and \(F\) the fuzziness. The color distance is the one the Magic Wand uses. Localized colors add a factor. Each term is multiplied by \(\max(0, 1 - \delta_k / R)\), where \(\delta_k\) is the distance in pixels from the sample. \(R\) is the range setting in percent of the longer image side, turned into pixels.
The tone presets use BT.709 luma \(Y\) from 0 to 255:
where clamp limits the value to 0 to 1. The three weights add up to 1 for every \(Y\), so the presets split the tones without gaps.
Brightness. With the range \([L, H]\) and softness \(S\), the value is \(\min\big(\rho(L - Y; 0, S),\ \rho(Y - H; 0, S)\big)\).
Hue and saturation. The hue distance goes around the color circle, so 350 and 10 degrees are 20 degrees apart. The value is the smallest of three ramps: the hue distance against the hue width, and the distances of saturation and value outside their ranges. The softness applies to each, in degrees for hue and percent for the others. A hue width of 180 accepts every hue.
Parameters¶
Color Range:
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Select preset |
Sampled colors | Sampled colors, Highlights, Midtones, Shadows | What to select. Sampled colors uses the colors you click. The tone presets use brightness. |
Tolerance tolerance |
0 | 0 to 255 | Color distance from a sample up to which a pixel is fully selected. |
Fuzziness fuzziness |
40 | 0 to 255 | Extra color distance over which the selection fades from full to none. |
Color space colorSpace |
Lab | RGB, HSV, Lab | Where the color distance is measured. |
Localized colors localized |
off | On or off | Weight each sample by how near the pixel is to the place you clicked. |
Range range |
25 | 1 to 100 % | For localized colors, how far a sample reaches, in percent of the longer image side. |
Select by brightness:
| Parameter | Default | Values | Meaning |
|---|---|---|---|
From low |
128 | 0 to 255 | Darkest brightness (BT.709 luma, 0 to 255) that is fully selected. |
To high |
255 | 0 to 255 | Brightest brightness (BT.709 luma, 0 to 255) that is fully selected. |
Softness softness |
16 | 0 to 128 | Brightness levels over which the selection fades outside the range. |
Select by hue and saturation:
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Hue hue |
0 | 0 to 360 deg | Center of the hue range on the color circle. 0 is red, 120 is green and 240 is blue. |
Hue width hueWidth |
30 | 0 to 180 deg | How far the hue may be from the center on each side. 180 accepts every hue. |
Saturation from saturationMin |
20 | 0 to 100 % | Lowest saturation that is fully selected. |
Saturation to saturationMax |
100 | 0 to 100 % | Highest saturation that is fully selected. |
Value from valueMin |
10 | 0 to 100 % | Lowest HSV value (the largest of R, G and B) that is fully selected. |
Value to valueMax |
100 | 0 to 100 % | Highest HSV value that is fully selected. |
Softness softness |
10 | 0 to 90 | Fade outside every range, in degrees for hue and percent for saturation and value. |
Implementation¶
The dialog previews the result on a copy of the image at most 240 pixels on the longer side. The color samples are read from the full image, so the preview uses the same colors as the final result. OK computes the selection at full size.
Limitations¶
- Color Range selects similar colors everywhere. Use localized colors to keep it near your samples.
- Gray pixels have no real hue. Keep the saturation minimum above 0 to leave them out of a hue selection.