Thresholding creates a binary segmentation by comparing one scalar image feature with a threshold. Otsu thresholding selects the threshold that gives the most compact pair of intensity classes.

Main idea

Otsu chooses the threshold with the smallest within-class variance. This is equivalent to choosing the largest between-class variance.


Simple Thresholding

For threshold :

The result is a binary mask. This extends the thresholding method in Point Processing > Method 4: Thresholding.

Threshold choiceResult under the rule above
Lower thresholdMore pixels satisfy and enter class 1
Higher thresholdFewer pixels satisfy and enter class 1

The displayed rule assigns dark values to class 0. If the selected object is dark, invert the binary result so the selected foreground becomes 1 and the background becomes 0.

Simple thresholding works well when foreground and background intensities are clearly separated. Uneven illumination and overlapping intensity distributions reduce its reliability.


Otsu Procedure

Otsu tests every candidate threshold that keeps both classes non-empty:

  1. Split the gray levels into a low-intensity class and a high-intensity class
  2. Calculate the probability, mean, and variance of each class
  3. Calculate the weighted within-class variance
  4. Choose the threshold with the smallest weighted within-class variance

A good threshold gives two compact classes with large separation.


Class Definitions

Use the same boundary convention as the binary rule above:

Let be the probability of gray level . The class probabilities are:

The tested threshold must keep both classes non-empty:

Skip a threshold that makes either class probability zero because its class mean and variance would be undefined.

The class means are:


Global Mean and Variance

The global mean uses the complete histogram:

The global variance is:

Equivalently:

Both quantities are independent of because they use all gray levels. The threshold changes only the division into the two classes.


Show That the Global Mean Is the Weighted Class Mean

From the class-mean definitions:

Add the two equations:

Therefore:


Within-Class Variance

The two class variances are:

The weighted within-class variance is:

Each term combines the size of a class with the variation inside that class.

Derive

Similarly:


Between-Class Variance

The between-class variance is:

It measures the weighted separation of the two class means from the global mean. It can also be written as:

A large value occurs when the two class means are far apart and both classes have substantial probability.


Why the Two Otsu Objectives Are Equivalent

The global variance separates into within-class and between-class parts:

For one image histogram, is constant for every threshold. Therefore:

Otsu can therefore search for either:

  • The minimum within-class variance
  • The maximum between-class variance

Both searches select the same threshold.

Otsu still depends on the intensity distribution

Otsu is most effective when two intensity classes are well separated. Uneven illumination or strongly overlapping classes can produce an unsuitable global threshold.

The output can be processed further with morphology when the binary mask contains small holes, gaps, or foreground speckles.