This command finds pixels which more-or-less match a reference color, according to a given tolerance, returning a single channel, bi-value image (1, 0 or 'True', 'False') where unitary pixels ('True') indicate that the corresponding pixel in the original image is within the given the tolerance.

The graphic on the far left depicts balloons over Château-d’Œx in the canton of Vaud, Switzerland, and is an eight bit, unsigned integer RGB image. The command -select_color[-1] 20%,230,233,147 identifies a pale yellow reference color similar to the top half of the middle balloon. The near-left image shows the output of the command; White identifies pixels with colors within a twenty percent range of the specified color, the given tolerance. Black identifies pixels outside this range, with colors too unlike the pale yellow to merit consideration.

The -distance command gives an example of using -select_color. See "Application: Modifying a Warning Image" in that article. Also, see the Theory section below.

The format of the command is:

-select_color tolerance[%]>=0,col1,..,colN

The image produced by -select_color is bi-valued, its pixels either zero or one and would not work well in paint programs. Use -normalize 0,255, or similar, if the output is intended for use as a mask in a paint program. See "Images as Datasets".


The command builds a difference image by subtracting the reference color, composed as a constant color image, from the original image, then applies -norm to the difference image, generating a single channel gray scale image of vector lengths, a vector field. the command interprets the tolerance parameter as a maximum admissable length of vectors, representing colors more or less like the reference color. Here is a detailed walkthrough of -select_color's internal pipeline:


An RGBA image of a flower, an image stack item.

gmic flower.png...


A reference color image selecting rgba(255,222,30,255), the darkest yellow petal on the flower in image 1. This color stems from the second parameter given to select_color and is used internally as a parameter to -fill_color.

...fill_color 255,222,30,255...


-select_color takes the difference between the original flower image and the constant color image. We depict a normalizedimage here; the visible colors are not very meaningful. Internally, this differences image will exhibit both positive and negative intensities in each channel. The dark yellow petal, exactly equal to the reference color, now has a value of rgba(0, 0, 0, 0), but in this normalized image, appears to be a rather warm gray instead of black.



This image results from the -normcommand operating on image 3, above and is a data set of vector lengths, a single channel gray scale, with the smallest-length vectors very nearly black. These small vectors correspond to pixels in the original image (1) that are very much like the reference color (2).



The first parameter given to -select_color, tolerance, is used at the end of the pipeline as a parameter to the logic command -le. This command produces a single channel, bi-value image, the output of -select_color, and indicates pixels with a magnitude of 32 or less, corresponding to those in the original image (1) with color space distances equal to or less than 32 pixels from the reference color (2). With this absolute tolerance of 32 pixels, two petals fall within the range of interest, the one with the reference color, of course, at a distance of zero from itself, and an another with a very similar color (255, 249, 45, 255), at a distance of 30.89 pixels from the reference color. All other colors are out of tolerance.

...-le 32


This single channel, bi-value image arises from an alternate tolerance parameter of 128 pixels, reflecting a somewhat more encompassing tolerance that selects vector lengths from image 4 with a magnitude of 128 or less, corresponding to pixels in the original image (1) with color space distances equal to or less than 128 pixels away from the reference color. All petals qualify as well as the center of the flower, though its color is more orange-red than yellow. At (255,136,83,255), it is 101.02 pixels away from the reference color. Clearly, the 128 pixel sphere around the reference color accommodates many, not particularly yellow-like colors.

...-le 128

Image:Balloon Festival, January 2006 at Château-d’Œx, Switzerland.  Jamie Crespo (jynus) Wikimedia Commons

Garry Osgood