Otsu's method

From Wikipedia, the free encyclopedia

Otsu's method or Otsu's algorithm or Ad-hoc algorithm is used in computer vision and medical image processing to perform thresholding. It designed to separate foreground from background.

If each pixel p of an image has been assigned an 'interest' (or number of occurrences) score, f(p) then Otsu creates a histogram of f over the image; and selects a threshold to maximize the between-class variance. The method is non-iterative and relies on the assumption that all image pixels belong to one of two classes, background or foreground (i.e. object(s)).

The method was originally described in: N. Otsu, “A threshold selection method from gray-level histograms,” IEEE Trans. Sys., Man., Cyber., vol. 9, pp. 62–66, 1979.

[edit] Otsu's Method Interpretation

 Step through all intensity levels in histogram
   Set T (between-class threshold) to current intensity level
   Compute between-class variance (e.g. derived from zeroth and first order cumulative moments of the histogram, on each side of current level)
 Otsu threshold level is that for which between-class variance is maximum

[edit] Pseudo-code implementation

FG = Foreground, BG = Background, FGregion = Foreground Region, BGregion = Background Region, T = Threshold

Initialise FGregion & BGregion (BGregion is usually the four corners of an image).
While T remains unchanged.
  Find the mean intensity of each region.
  T = ( Fmean + Bmean ) / 2.
  Recalculate the regions:
    FGregion = pixels that their intensity is >= to T.
    BGregion = pixels that their intensity is < to T.