8.53. Llindar

The Threshold filter transforms the current layer or the selection into a black and white image, where white pixels represent the pixels of the image where the value for the chosen Channel is in the threshold range, and black pixels represent pixels with a value outside the threshold range.

Podeu utilitzar-la per a millorar una imatge en blanc i negre (per exemple, text escanejat) o per a crear màscares de selecció.

[Nota] Nota

As this filter 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.53.1. Activating the Filter

There are different possibilities to activate this:

  • This filter is found in the image window menu under ColorsThreshold…,

  • or by clicking the icon in the Toolbox if Threshold has been enabled as a tool (which is disabled by default). For this, please refer to Secció 1.13, «Caixa d'eines».

8.53.2. Opcions

Figura 16.247. Threshold filter dialog

Threshold filter dialog

Predefinits

«Presets» are a common feature for several Colors commands. You can find its description in Secció 8.1.1, «Característiques comunes dels colors».

Canal

This allows you to select which channel(s) will be used to apply the Threshold. The default is Value, which will use all color channels, but you can also choose to use a single channel: Red, Green, Blue and Alpha (only available when the layer has an alpha channel), Luminance, or RGB.

Linear Histogram, Logarithmic Histogram

These two buttons to the right of the Channel selection let you choose the type of histogram shown.

Interval del llindar

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 minimum and maximum input boxes, or by clicking 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. The Auto button can be used to automatically adjust the threshold.

Blending Options, Preview and Split view

These are common features described in Secció 8.1.1, «Característiques comunes dels colors».

8.53.3. Ús del Llindar i la Màscara ràpida per a crear una màscara de selecció

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 your image into its RGB and HSV components by using the Decompose filter. A new grayscale 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.

    Figura 16.248. La imatge original, la imatge descomposta i el diàleg de la capa

    La imatge original, la imatge descomposta i el diàleg de la capa
    La imatge original, la imatge descomposta i el diàleg de la capa
    La imatge original, la imatge descomposta i el diàleg de la capa

  2. Crideu l'eina llindar des de la imatge descomposta. Si moveu el cursor negre, ajusteu el llindar per a aïllar el millor element que vulgueu extreure. Probablement això no serà perfecte: millorarem el resultat amb la màscara de selecció que crearem.

    [Avís] Avís

    Assegureu-vos que heu seleccionat la capa adequada quan agafeu l'eina Llindar: quan s'ha obert, no podeu canviar a una altra capa.

    Figura 16.249. La capa seleccionada després d'ajustar el llindar

    La capa seleccionada després d'ajustar el llindar

    Tenim el millor contorn per a la nostra flor. Hi ha diversos objectes vermells que hem de treure.


  3. Assegureu-vos que la imatge que mostra la capa seleccionada estigui activa i copieu-la al porta-retalls amb Ctrl+C.

  4. Ara, feu que la imatge original sigui activa. Feu clic al botó Màscara ràpida de l'extrem inferior esquerre de la finestra de la imatge: la imatge es cobreix amb una màscara translúcida vermella (per defecte). Aquest color vermell no s'adapta bé a la nostra imatge amb molt vermell: aneu al diàleg del canal, activeu el canal «màscara ràpida» i canvieu aquest color amb els atributs d'edició del canal. Tornem a la imatge original. Premeu Ctrl+V per a enganxar la capa copiada anteriorment.

    Figura 16.250. La màscara

    La màscara

  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.

    Figura 16.251. El resultat

    El resultat
    El resultat

    We used the Zoom to work at a pixel level, Free Select 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.