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)
Image: Sydney Opera House from Dawes Point, Sydney, Australia. Greg O'Beirne, Wikimedia Commons.