Adaptive Thresholding of Images

Initializing live version
Download to Desktop

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram Player or other Wolfram Language products.

An adaptive threshold binarizes a grayscale image based on the local character of the image (which you can select from any of the photos in the Wolfram image library).


In this implementation, the adaptive method finds the mean value in each neighborhood. If the pixel value is greater than a threshold multiplied by this mean, the pixel is set to "1" (white), and otherwise is set to "0" (black). This changes a grayscale image to black and white. When applied to the three RGB channels of a color image, the result is a combination of an edge detection and a posterization; regions are outlined in bright colors.

With the infill option, the value of the central pixel is set to "0" (black), or it is left at the original value. This provides a dark halo around the edges of grayscale objects and sets a black outline around objects in a colored image.


Contributed by: William Sethares (November 2012)
Open content licensed under CC BY-NC-SA



The filter has two controls: the size of the neighborhood and the threshold value. As the neighborhood is decreased, smaller features are revealed. As the threshold is increased, the image reliably darkens (it is lighter as the threshold is decreased). The checkbox lets you compare the original image, the outlined-thresholded image, and the infilled version. The "detail" slider lets you choose between a smaller image (faster) and better fidelity (slower to calculate).

Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.