Main Content

Binarize 2-D grayscale image or 3-D volume by thresholding

creates a
binary image from 2-D or 3-D grayscale image `BW`

= imbinarize(`I`

)`I`

by replacing all
values above a globally determined threshold with `1`

s and setting
all other values to `0`

s. By default, `imbinarize`

uses Otsu's method, which chooses the threshold value to minimize the intraclass
variance of the thresholded black and white pixels [1].
`imbinarize`

uses a 256-bin image histogram to compute Otsu's
threshold. To use a different histogram, see `otsuthresh`

.

creates a binary image from image `BW`

= imbinarize(`I`

,'adaptive',`Name,Value`

)`I`

using name-value pairs to control
aspects of adaptive thresholding.

To produce a binary image from an indexed image, first convert the image to a grayscale image using

`ind2gray`

.

The `'adaptive'`

method binarizes the image using a locally adaptive
threshold. `imbinarize`

computes a threshold for each pixel using the local
mean intensity around the neighborhood of the pixel. This technique is also called Bradley's
method [2]. The `'adaptive'`

method also uses a neighborhood size of approximately 1/8th of the size of the image (computed as
`2*floor(size(I)/16)+1`

). To use a different first order local statistic or a
different neighborhood size, see `adaptthresh`

.

[1]
Otsu, N., "A Threshold Selection Method from Gray-Level
Histograms." *IEEE Transactions on Systems, Man, and Cybernetics*. Vol. 9,
No. 1, 1979, pp. 62–66.

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