Image - Threshold

Threshold converts each pixel into black, white or unchanged depending on whether the original color value is within the threshold range. Threshold is a very important command that is often used to prepare scanned RGB or RGBa images for vectorization or use as guide layers in the creation of drawings. It can be used with raster data images to set off ranges of values that may then be used for subsequent analysis or as selection masks.


images\img_525univ_mono.gif images\img_threshold_eg01.gif


This command is also available on the Transform Toolbar for images as the Threshold, Threshold Black and Threshold White transform operators. However, when used from the transform toolbar the effect is immediate with no preview possible. The parameter in the transform tool bar is used to set the threshold between white and black.



Shows distribution of intensity values. The taller the line, the more pixels have that intensity value.

[% number]

The percentage of pixels that are within the threshold range.

[Upper edit box]

Beginning of threshold range.

[Lower edit box]

End of threshold range.

[Left Mouse Click]

Clicking the left mouse button in the histogram sets the left side of the threshold range.

[Right Mouse Click]

Clicking the right mouse button in the histogram sets the right side of the threshold range.


Choose standard, black or white threshold operation.


Both - All pixels within range are forced white. All others are forced black.


Black - All pixels within range are unchanged. All others are forced black.


White - All pixels within range are forced white. All others are left unchanged.


Check to see effect in action.




The two edit boxes set the lower and upper bounds of the threshold range.




Changing the lower box's value from 255 to a lower amount will constrict the threshold range. In the example above, all pixel values with intensity lower than 107 and all those with intensity 141 will be forced black. All those in between will be forced white. The white pixels will be 30% of the pixels in the image.




The result is an image where all intensities except those middle intensities are black.


Black and White Options


Choosing the Black option restricts the action of the Threshold command to only those pixels that are to be forced black. All other pixels are left unchanged. For example, using the threshold range above all pixels in intensity from 107 to 141 will be left unchanged. All other pixels will be forced black.


The White option restricts the action of the Threshold command to only those pixels that are to be forced white. In the above example, all pixels from 107 to 141 will be forced white. All other pixels will be left unchanged.


Use with Color Images


Threshold may be applied to RGB or other multi-channel images. When applied to color images, the histogram shows the intensity level of pixels. For per-channel control of threshold in color images, use the Threshold Color command.




We begin with the sample schloss image. "Schloss" is German for "castle" or "chateau." The image shows the famous fairy-tale castle, Schloss Neuschwannstein, built by King Ludwig in Bavaria.




The histogram for this image shows that over 40% of the pixels are clustered about a very high intensity. These are obviously the pixels that make up the sky in very high intensity, blue-white colors. We've moved the range controls so that for the most part only the sky pixels will be in range.




The Both setting forces all pixels in range to white and all those out of range to black. Since the range ends at 255, there are no pixels above the range. Only darker pixels are below.




Using the Black setting changes those pixels that are out of range to black and leaves those pixels in range unmodified. These are the sky pixels, which are left in their original light, blue-white colors.




Using the White setting changes those pixels in-range to white and leaves all other pixels unmodified. The above illustration looks similar to the original but on close examination will be seen to have only pure white pixels in the sky where colors used to be light, blue-white tones.




By careful selection of ranges, we can choose only a limited range of intensities to be forced white with all other pixels forced black. For example, the above range will leave only a limited range in white with all intensities above and below the range forced black.




The result is that we have picked out a particular range of intensities in the image. Note how both the very light sky (above the designated range in intensity) as well as the ground and trees (below the range) have both been forced black.


A Cartographic Example




Using a scanned image of a map as an example (a USGS DRG map) we can use threshold to suppress details except for the pink colors.




A bit of interactive experimentation shows that the intensity peak selected in the range in the histogram shown above is associated with the many pixels in the image in pink shades, all of which have about the same intensity.




Using Black as the modify operator, we force all pixels outside the narrow range to black, leaving only those within the intensity range as pink.




We can move the range to other "bumps" in the histogram to pick out other pixels by intensity ranges.




This range of intensities corresponds to the purple tones.




The next bump in the histogram corresponds to darker red tones.




In all the above examples, we force pixels outside the range to pure black color. This makes it easy to select those pixels using Select Touch and to delete them. Alternately, we could Invert the image to force them to white to make our job of vectorizing a set of lines that much easier. Note the profound simplification of the image in the last example. Note also there is nothing that stops us from using Threshold several times to pick out different "slices" of the image and to then combine them (perhaps after other operations such as Invert) to get exactly the image we want to use for vectorization. Very often the desired result will be reached by combining several commands.


In the above sequence it is tempting to imagine we picked out a particular color to be forced white; however, this is not the case. We have simply picked out a range of intensities. It is often the case in photographic images that particular colors or regions fall into similar intensity ranges so we can exploit this effect sometimes by using intensity as a proxy for color values. For threshold selection by true color values, use the Threshold Color command.


Another way of picking out particular color tones would be to use Select Touch to pick out all the pixels in dark red color. We could then choose Edit - Select Inverse to invert the selection and thus select all pixels except those in dark red color. Next, we could delete the selected pixels or use the Brightness / Contrast control to set the brightness of the selected pixels to zero, which would make them all black. There are often several different methods we can use in Manifold to achieve a desired result. Which method we choose depends on what is most convenient and most accurate at the time.




A reminder: Like all Manifold commands, Threshold will work only on the selected pixels if a selection is present.


images\img_threshold_eg03.gif images\img_threshold_eg04.gif images\img_threshold_eg05.gif


In the sequence above, we've selected a "5" shaped region of pixels, applied Threshold and then turned off selection color so the effect can be seen. Cool!