Binarize

Binarize[image]

creates a binary image from image by replacing all values above a globally determined threshold with 1 and others with 0.

Binarize[image,t]

creates a binary image by replacing all values above t with 1 and others with 0.

Binarize[image,{t1,t2}]

creates a binary image by replacing all values in the range t1 through t2 with 1 and others with 0.

Binarize[image,f]

creates a binary image by replacing all channel value lists for which f[v] yields True with 1 and others with 0.

Details and Options

  • Binarization using a global threshold is one of the most common segmentation techniques.
  • Binarize converts multichannel and color images into grayscale images, then produces an image in which every pixel has value 0 or 1.
  • Binarize works with arbitrary 2D and 3D images.
  • Binarize[image,{t,t}] effectively sets pixels with value t to 1 and all other pixels to 0.
  • In Binarize[image,f], the function f is applied to the list of channel values for each pixel.
  • Binarize[image] uses Otsu's cluster variance maximization method. Other possible settings for the Method option include:
  • {"BlackFraction",b}replace a fraction b of all pixels with black
    "Cluster"cluster variance maximization (Otsu's algorithm)
    "Entropy"histogram entropy minimization (Kapur's method)
    "Mean"use the mean level as the threshold
    "Median"use the median pixel level as the threshold
    "MinimumError"KittlerIllingworth minimum error thresholding method
  • If an explicit threshold value is given, Binarize ignores the Method option. »

Background & Context

  • Binarize creates a two-level (binary) version of an image whose pixel values correspond to 0s and 1s. Binarize enhances contrast and is typically used for feature detection, image segmentation, or as a preprocessing step prior to application of other image processing functions.
  • Binarize is particularly effective when all foreground pixels have higher intensity values than background pixels. It is a pixel (or point) operation, meaning it is applied to each pixel independently.
  • Binarize implements intensity thresholding and other binary segmentation methods for images and can operate either automatically or given explicit cutoff values. Applying Binarize removes any alpha channel present and produces an image having a single channel.
  • Other more advanced binary segmentation functions include MorphologicalBinarize, RegionBinarize, and ChanVeseBinarize.

Examples

open allclose all

Basic Examples  (2)

Convert a color image to binary:

Use a specific threshold:

Scope  (8)

Data  (3)

Automatic binarization of a greyscale image:

Automatic binarization of a color image:

Automatic binarization of a 3D image:

Parameters  (5)

Binarize a color image with an explicit threshold:

Find pixels with intensities in a range of given values:

Threshold 0 sets all nonzero values to 1:

Set all non-white pixels to black:

Find pixels where the red channel is larger than the green channel:

Options  (6)

Method  (6)

Use a threshold computed with Otsu's method:

Use KittlerIllingworth's minimum error method to classify pixels drawn from two Gaussian distributions:

Kapur's entropy method:

Use the average intensity value as threshold:

Use the median intensity value as threshold:

Try the black fraction method with different fractions:

Due to quantization, the actual fraction of black pixels may be slightly different:

Applications  (4)

Binarize a gradient image with a specific black fraction to find the strongest edges:

Create an alpha channel:

Use Binarize to get the high intensity pixels:

Remove small pieces and use as mask:

Segment objects in an image:

Compute centroid of each component:

Segment components of a specific color in an image:

Properties & Relations  (8)

The interpretation of the specified threshold is the same for all image data types:

With color images, the thresholding is performed on intensity values:

For multichannel images with ColorSpace->Automatic, the mean of channel values is used:

In Binarize[image,f], pixel values are passed to f regardless of the color space of image:

If both threshold and Method are specified, Method setting is ignored:

Binarize operates on pixel values regardless of pixels' positions and pixels' neighbors:

Using MorphologicalBinarize, darker pixels connected to lighter pixels are also set to 1:

ChanVeseBinarize finds optimal contours around regions of consistent color:

Implement an intensity thresholding using ImageApply:

Possible Issues  (1)

A function that returns 0 and 1 cannot be used as a valid thresholding function:

Output pixels are white if and only if the function returns True:

Interactive Examples  (1)

Interactively compare different Method settings:

Wolfram Research (2008), Binarize, Wolfram Language function, https://reference.wolfram.com/language/ref/Binarize.html (updated 2012).

Text

Wolfram Research (2008), Binarize, Wolfram Language function, https://reference.wolfram.com/language/ref/Binarize.html (updated 2012).

CMS

Wolfram Language. 2008. "Binarize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/Binarize.html.

APA

Wolfram Language. (2008). Binarize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Binarize.html

BibTeX

@misc{reference.wolfram_2024_binarize, author="Wolfram Research", title="{Binarize}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/Binarize.html}", note=[Accessed: 15-October-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_binarize, organization={Wolfram Research}, title={Binarize}, year={2012}, url={https://reference.wolfram.com/language/ref/Binarize.html}, note=[Accessed: 15-October-2024 ]}