8.52. Threshold

The Threshold tool transforms the current layer or the selection into a black and white image, where white pixels represent the pixels of the image whose Value is in the threshold range, and black pixels represent pixels with Value out of the threshold range.

You can use it to enhance a black and white image (scanned text for example) or to create selection masks.

[Note] Note

As this tool creates a black and white image, the anti-aliasing of the original image disappears. If this poses a problem, use the Levels tool instead.

8.52.1. Activating the Tool

There are different possibilities to activate the tool:

  • You can access this tool from the image menu through ColorsThreshold…,

  • or by clicking the icon in Toolbox if this tool has been installed in it. For this, please refer to Section 1.11, “Toolbox”.

8.52.2. Options

Figure 16.236. Threshold tool options

Threshold tool options

Presets

You can save the color settings of your image by clicking the Add settings to favourites button

The button opens a menu:

Figure 16.237. Preset Menu

Preset Menu

which lets you Import Settings from File or Export Settings to File, and gives you access to the Manage Saved Presets dialog:

Figure 16.238. Manage saved Settings Dialog

Manage saved Settings Dialog

Threshold range

The Threshold tool provides a visual graph, a histogram, of the intensity value of the active layer or selection. You can set the threshold range either using the input boxes or clicking button 1 and dragging on the graph. It allows you to select a part of the image with some intensity from a background with another intensity. Pixels inside the range are white, and the others are black. Adjust the range to get the selection you want in white on black background.

Preview

The Preview checkbox allows dynamic updating of the active layer or selection while changes are made to the intensity level.

8.52.3. Using Threshold and Quick Mask to create a selection mask

That's not always the case, but an element you want to extract from an image can stand out well against the background. In this case, you can use the Threshold tool to select this element as a whole. Grokking the GIMP described a method based on a channel mask, but now, using the Quick mask is easier.

  1. First start decomposing you image into its RGB and HSV components by using the Decompose filter. A new grey-scaled image is created and the components are displayed as layers in the Layer dialog. These layers come with a thumbnail but it is too small for an easy study. You can, of course, increase the size of this preview with the dialog menu (the small triangular button), but playing with the eyes is more simple to display the wanted layer in the decompose image. Select the layer that isolates the element the best.

    Figure 16.239.  The original image, the decompose image and its Layer Dialog

    The original image, the decompose image and its Layer Dialog
    The original image, the decompose image and its Layer Dialog
    The original image, the decompose image and its Layer Dialog

  2. Call the Threshold tool from the decompose image. By moving the black cursor, fit threshold to isolate the best the element you want to extract. This will probably not be perfect: we will enhance the result with the selection mask we are going to create.

    [Warning] Warning

    Make sure you have selected the right layer when you call the Threshold tool: when it is opened, you can't change to another layer.

    Figure 16.240. The selected layer after threshold fit

    The selected layer after threshold fit

    We got the best outline for our flower. There are several red objects which we must remove.


  3. Make sure the image displaying the selected layer is active and copy it to the clipboard with Ctrl+C.

  4. Now, make the original image active. Click the Quick Mask button at the bottom-left corner of the image window: the image gets covered with a red (default) translucent mask. This red color does not suit well to our image with much red: go to the Channel Dialog, activate the Quick mask channel and change this color with the Edit Channel Attributes. Come back to the original image. Press Ctrl+V to paste the previously copied layer.

    Figure 16.241. The mask

    The mask

  5. Voilà. Your selection mask is ready: you can improve the selection as usual. When the selection is ready, disable the Quick mask by clicking its button again : you will see the marching ants around the selection.

    Figure 16.242. The result

    The result
    The result

    We used the Zoom to work at a pixel level, the Lasso to remove large unwanted areas, the pencil (to get hard limits), black paint to remove selected areas, white paint to add selected areas, especially for stem.