How GIMP Select by Color Calculates RGBA Similarity

GIMP’s Select by Color tool allows users to isolate pixels across an image based on matching color characteristics. While the default mode compares overall composite color distance, setting the tool to evaluate individual Red, Green, Blue, or Alpha channels changes the calculation from a multi-dimensional geometric distance to a direct scalar comparison. This article explains the exact mathematical and operational process GIMP uses to determine pixel similarity when targeting individual RGBA components.

The Reference Point and the Threshold

When you click on an image using the Select by Color tool, GIMP samples that specific pixel as the reference (or "seed") value. The user-defined Threshold setting determines the maximum allowable deviation from this reference point.

In GIMP, channel values internally range from 0.0 to 1.0 (in floating-point precision) or 0 to 255 (in standard 8-bit representation). The Threshold slider corresponds directly to these units, defining the boundary of acceptance for candidate pixels.

The Single-Channel Calculation Formula

When the "Select by" option in the Tool Options dialog is set to a single component—Red, Green, Blue, or Alpha—GIMP discards all other channels during evaluation.

Instead of measuring Euclidean distance across 3D color space (as it does in Composite mode), GIMP calculates a simple absolute difference along a one-dimensional axis:

\[\text{Difference} = |C_{\text{candidate}} - C_{\text{reference}}|\]

Where:

  • \(C_{\text{reference}}\) is the value of the chosen channel at the clicked pixel.
  • \(C_{\text{candidate}}\) is the value of the chosen channel at any given pixel in the image.

A candidate pixel is selected if the difference is less than or equal to the Threshold:

\[\text{Difference} \le \text{Threshold}\]

Behavior by Specific Component

  • Red, Green, or Blue: When one of these color channels is chosen, GIMP evaluates only the intensity of that specific primary color. For example, if you select by the Red channel, a pure red pixel (255, 0, 0) and a pure yellow pixel (255, 255, 0) are considered identical (both have a Red value of 255), regardless of their vastly different appearances to the human eye. The green and blue components are completely ignored.
  • Alpha: When set to Alpha, GIMP inspects solely the opacity layer of the image. The visible color values (Red, Green, and Blue) are entirely disregarded. A fully opaque black pixel and a fully opaque white pixel have an Alpha difference of zero and will both be selected, while a semi-transparent pixel will be evaluated strictly on its degree of transparency relative to the reference pixel.

Antialiasing and Selection Weight

By default, the selection results in a binary state: a pixel is either fully selected (value within threshold) or not selected.

If Antialiasing is enabled, GIMP calculates partial selection values (feathered edges) for pixels that fall near the outer boundary of the threshold. Instead of a hard cutoff, candidate pixels near the threshold limit receive a fractional selection weight between 0% and 100%, producing smoother transitions along selection borders.