# -threshold

Threshold sets pixels with intensities less than a given cutoff value to zero. Two variants determine how the remaining pixels are treated.

In the 'soft' command variant (middle slice, left), threshold subtracts the cutoff intensity, c, from the image and then sets pixels with negative intensities to zero. In the middle slice, the cutoff intensity was 127, which -threshold subtracted from the image, then set all pixels with intensities less than zero to zero, in essence using the -cut command. The operation put the middle slice maximum intensity at 127 from an original value of 254.

In the 'hard' variant of the command (righthand slice), threshold sets all intensities less than the cutoff to zero (127 again) and intensities equal to or greater than the cutoff to one. It converts the channel to a binary dataset with 0 or 1 values. The hard variant of threshold often prepares masks, but for use in other paint programs, it is prudent to normalize the output of the hard variant to a range compatible with the paint program, typically 0,255 for 8 bit programs such as Gimp 2.8.

It is possible to use -threshold without parameters. This brings up the display window (see -display). One may press left mouse button down in the display window and drag the pointer to the left and right to interactively set the threshold. Releasing the left mouse button sets the threshold at the last value derived from mouse movements.

Threshold may operate on multi-channel (multi-spectral) images in both soft and hard modes. In this case, the command operates independently on each channel. Threshold also works along the depth dimension, supporting multi-slice images.

The format of the command is:

-threshold: value[%],_is_soft | (no args)

• value: Specifies the cutoff intensity below which image pixels are set to zero. May be expressed as an absolute intensity, or in percentage terms, where it expresses the fractional part of the interval, iM − im, between an image's maximum value iM and minimum value im.
• _is_soft: an optional boolean flag. When zero, the default, -threshold produces binary images where input pixels at or exceeding the threshold value are set to logical one ('True') in the output channel, and are otherwise set to zero ('False'). When one, -threshold produces grayscale images with new intensities reduced from the old by a difference equal to the cutoff and with negative values set to zero. In this mode, the new maximum intensity relates to the old in the following way: i'M = iMc, for c, the cutoff value.

Image: Sydney Opera House from Dawes Point, Sydney, Australia. Greg O'Beirne, Wikimedia Commons.

Garry Osgood