Compute local threshold value for each pixel using local mean intensity in the neighborhood of each pixel.
Parameters:
Input image, specified as a 2-D grayscale image. Image type can be int8, uint8, int16, uint16, int32, uint32, single or double.
Sensitivity factor, specified as a scalar in the range [0, 1]. Higher values make the threshold more sensitive, resulting in more foreground pixels. Default value = 0.5
Additional options as name-value pairs:
Method used to compute the threshold. Valid options are:
Computes the threshold based on the local mean intensity. This method assumes that the foreground and background have different mean intensities.
Computes the threshold using the local median intensity. This method is more robust to noise and outliers compared to the mean method.
Uses a weighted average where weights are determined by a Gaussian window. This method smooths the local intensity variations and can be more effective in noisy images.
Size of the local neighborhood, specified as a positive scalar or a 2-element vector [m n]. m & n should be odd integers. By default, the window size is determined based on the size of the input image. For an image of size MxN, the default window size is computed as:
m = 2 * floor (M / 16) + 1 n = 2 * floor (N / 16) + 1
This ensures the window size is odd and appropriately scaled relative to the image dimensions.
Defines object polarity:
Outputs
Thresholds image, where each pixel present the normalized intensity.
The values of T are in the range [0, 1]
Example
I = imread ("example.png"); T = adaptthresh (I, 0.5, "Statistic", "mean", "NeighborhoodSize", [15 15]); BW = imbinarize (I, T); imshow (BW);
See also: imbinarize, graythresh, imboxfilt, medfilt2, imgaussfilt.
Package: image