# Can anyone explain the logic behind the Threshold option in the color picker?

I’m using the composite selection that I assume is a composite RGB value. The default is 15 for the threshold. Does that mean 15 pixels radius from the selected color or something else?

It is GIMP 2.10.38.

AFAIK is it is some “distance”. The color you provide is seen as a point in 3D space with R,G, and B coordinates. To know if a give pixels is selected, is is also plotted in the same 3D space and the distance to your reference color is computed (sum of squares of differences). If below the threshold (so inside a sphere around the reference color the pixels is selected. Not accounted for in explanation: whether the three colors are treated identically (green could be more important) and whether this is done in linear or gamma-corrected space.

Usually very overlooked: the other criteria (individual color channels or component in other color models) can work much better than composite in many case (if you pick the right one).

1 Like

Thank you. I think we’re on the same wavelength.

I am confused, what is the composite selection in GIMP?

It is a criterion (the default one) of color likeness used in the Fuzzy and By-Color selection tools.

1 Like

Eventually found the source code. For Composite it looks like this:

case GIMP_SELECT_CRITERION_COMPOSITE:
for (b = 0; b < n_components; b++)
{
diff = fabs (col1[b] - col2[b]);
if (diff > max)
max = diff;
}
break;
//* [Snip other "case" statements]

if (max > threshold)
return 0.0;
else
return 1.0;

So it is really if the difference between the R/G/B values are all within the threshold, so it’s more a cube than a sphere. In addition, the col[] values are likely not the direct channel values (experimentally they aren’t the [0..255] gamma-corrected color values) because the code for other criteria (Luminosity, etc…) also use the values directly so they are pre-computed elsewhere.

Thanks @Ofnuts for explaining what was being discussed and the mathematics behind it. @GCHerman56 in practical terms if you lower the threshold the color you are matching must be a closer match to the color used in the selection. If you increase the threshold the tolarance for difference in color or brightness of the color increases and the selection is larger.

Here a low threshold on the blue sky selects a very limited amount of the blue sky due to the drop off of light towards the corners of the frame as a result of the lens design. Non selection shown in red.

Here a higher threshold has selected the whole sky but not the helicopter which wasn’t similar enough in color to the blue sky. I don’t understand the math but that is how I use the threshold slider. The default value of 15 is an arbitrary starting point.

1 Like

This is great. I’m considering using this program to filter satellite imagery (NDWI) and need to be able to communicate the logic used. So my thinking is that the threshold (t) specifies the + or -integer value spread for R, G, and B from the target selection. So if it’s RGB 155,155,155, the threshold of 5 would pick all colors +and- from that? R 150-160, etc.?

So if it’s RGB 155,155,155, the threshold of 5 would pick all colors +and- from that? R 150-160, etc.?

Yes, it appears to.

@ Ofnuts… Thank you for helping clarify that. I suppose I’ll have to test that because the derivative map has pixels that would seem to exceed the threshold range, but it’s also close enough to satisfy this geologist.

One thing I learned in years of using Gimp is to never trust my eyes. The two tools I use most in Gimp are the Pointer and Histogram dialogs. They alone hold the truth.

2 Likes