Function File: BW = imbinarize (I)
Function File: BW = imbinarize (I, threshold)
Function File: BW = imbinarize (I, method)
Function File: BW = imbinarize (…, name, value, …)

Convert an image to a binary image using a specified thresholding method.

Inputs

  • I – The input image, which is a grayscale image. Image type can be int8, uint8, int16, uint16, int32, uint32, single or double. imbinarize currently supports RGB images with "global" option (see below) but only 2D grayscale image inputs with option "adaptive"
  • method – A string specifying the thresholding method. Possible values are "global" (default) or "adaptive" (optional).
  • threshold – (Optional) A scalar value representing the global threshold, or a matrix in the size of the image that presents the local threshold. If not specified, the threshold is calculated according to the method.
  • sensitivity – (Optional, used with "adaptive") A scalar value in the range [0, 1] that specifies the sensitivity for adaptive thresholding. Higher values result in more sensitive thresholding. Default is 0.5.
  • foregroundPolarity – (Optional, used with "adaptive") A string specifying the polarity of the foreground. Possible values are "bright" (default) or "dark". This determines which pixel values are considered foreground.

Outputs

  • BW – The resulting binary image. It is a logical array where pixels with values greater than the threshold are set to 1 (true) and others to 0 (false). For "adaptive" mode, it uses local thresholding.

Example

I = imread("image.png");
BW = imbinarize(I);
BW_global = imbinarize(I, "global");  # same as imbinarize(I)
BW_adaptive = imbinarize(I, "adaptive");
BW_thresh_08 = imbinarize(I, 0.8);

See Also

See also: graythresh, adaptthresh, im2bw.

Package: image