Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Adaptive image threshold using local first-order statistics

## Description

example

T = adaptthresh(I) computes a locally adaptive threshold that can be used with the imbinarize function to convert an intensity image to a binary image. The result, T, is a matrix the same size as I containing normalized intensity values in the range [0,1]. adaptthresh chooses the threshold based on the local mean intensity (first-order statistics) in the neighborhood of each pixel.

example

T = adaptthresh(I,sensitivity) computes a locally adaptive threshold with sensitivity factor specified by sensitivity. sensitivity is a scalar in the range [0,1] that indicates sensitivity towards thresholding more pixels as foreground.

example

T = adaptthresh(___,Name,Value) computes a locally adaptive threshold using name-value pairs to control aspects of the thresholding.

example

T = adaptthresh(V,___,Name,Value) computes a locally adaptive threshold for the 3-D input volume V.

## Examples

collapse all

Read image into the workspace.

Use adaptthresh to determine threshold to use in binarization operation.

T = adaptthresh(I, 0.4);

Convert image to binary image, specifying the threshold value.

BW = imbinarize(I,T);

Display the original image with the binary version, side-by-side.

figure
imshowpair(I, BW, 'montage')

Read image into the workspace.

Using adaptthresh compute adaptive threshold and display the local threshold image. This represents an estimate of average background illumination.

figure
imshow(T)

Binarize image using locally adaptive threshold

BW = imbinarize(I,T);
figure
imshow(BW)

Load 3-D volume into the workspace.

V = mristack;

Display the data.

figure
slice(double(V),size(V,2)/2,size(V,1)/2,size(V,3)/2)
colormap gray

Calculate the threshold.

J = adaptthresh(V,'neigh',[3 3 3],'Fore','bright');

Display the threshold.

figure
slice(double(J),size(J,2)/2,size(J,1)/2,size(J,3)/2)
colormap gray

## Input Arguments

collapse all

Input intensity image, specified as a real, nonsparse, 2-D matrix. If the image contains Infs or NaNs, the behavior of adaptthresh is undefined. Propagation of Infs or NaNs might not be localized to the neighborhood around Inf or NaN pixels.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Determine which pixels get thresholded as foreground pixels, specified as a real, nonnegative numeric scalar in the range [0,1]. High sensitivity values lead to thresholding more pixels as foreground, at the risk of including some background pixels.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Input intensity volume, specified as a real, nonsparse, 3-D array. If the image contains Infs or NaNs, the behavior of adaptthresh is undefined. Propagation of Infs or NaNs might not be localized to the neighborhood around Inf or NaN pixels.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: T = adaptthresh(I,0.4,'ForegroundPolarity','dark');

Size of neighborhood used to compute local statistic around each pixel, specified as a real, numeric, scalar, or two-element vector of positive odd integers.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Determine which pixels are considered foreground pixels, specified using either of the following:

Value

Meaning

'bright'

The foreground is brighter than the background.

'dark'

The foreground is darker than the background

Data Types: char | string

Statistic used to compute local threshold at each pixel, specified as one of the following:

Value

Meaning

'mean'

The local mean intensity in the neighborhood. This technique is also called Bradley’s method [1].

'median'

The local median in the neighborhood. Computation of this statistic can be slow. Consider using a smaller neighborhood size to obtain faster results.

'gaussian'

The Gaussian weighted mean in the neighborhood.

Data Types: char | string

## Output Arguments

collapse all

Normalized intensity values, returned as a 2-D matrix or 3-D array of class double. The return value T is the same size as the input image or volume.

## References

[1] Bradley, D., G. Roth, "Adapting Thresholding Using the Integral Image," Journal of Graphics Tools. Vol. 12, No. 2, 2007, pp.13-21.