encyclopegia.org

Otsu's method

In computer vision and image processing, Otsu's method , named after , is used to perform automatic image thresholding.[src] In the simplest form, the algorithm returns a single intensity threshold that separate pixels into two classes foreground and background.[src] This threshold is determined by minimizing intra-class intensity variance, or equivalently, by maximizing inter-class variance.[src] Otsu's method is a one-dimensional discrete analogue of Fisher's discriminant analysis, is related to Jenks optimization method, and is equivalent to a globally optimal k-means performed on the intensity histogram.[src] The extension to multi-level thresholding was described in the original paper, and computationally efficient implementations have since been proposed.[src]

In computer vision and image processing, Otsu's method , named after , is used to perform automatic image thresholding.[src] In the simplest form, the algorithm returns a single intensity threshold that separate pixels into two classes foreground and background.[src] This threshold is determined by minimizing intra-class intensity variance, or equivalently, by maximizing inter-class variance.[src] Otsu's method is a one-dimensional discrete analogue of Fisher's discriminant analysis, is related to Jenks optimization method, and is equivalent to a globally optimal k-means performed on the intensity histogram.[src] The extension to multi-level thresholding was described in the original paper, and computationally efficient implementations have since been proposed.[src] ==Otsu's method== Let, H be the normalised histogram of the pixels in an image (s.t.[src] it becomes the probability distribution of pixel intensities) with L bins.[src] There are two classes of this histogram: C_0 for background pixels, and C_1 for foreground pixels.[src] The primary disciminator of pixels (to assort them into classes) is the threshold t .[src] C_0 includes pixels from 0 to (t-1) , and C_1 includes from t to (L-1) .[src] The algorithm is then global search for an optimal threshold t^* such that intra-class variance (variance of pixels intensities in C_0 or C_1 ) is minimised.[src] Let, \omega_0 denote the cumulative probability of C_0 , and \omega_1 denote of C_1 .[src] \begin{align} \omega_0(t) & =\sum_{i=0}^{t-1} P(i), \\ \omega_1(t) & =\sum_{i=t}^{L-1} P(i).[src] \end{align} For a classes C_0 and C_1 , the conditional probability of selecting the i -th pixel in those classes is P(i | C_0) and P(i | C_1) respectively.[src] Now, let \mu_0(t) and \mu_1(t) be the mean (pixel intensity) of C_0 and C_1 respectively.[src] \begin{align} \mu_0(t) &= \sum^{t-1}_{i=0} iP(i | C_0) = \sum^{t-1}_{i=0} \frac{iP(i)}{\omega_0(t)} = \frac{\sum^{t-1}_{i=0} iP(i)}{\omega_0(t)}.[src] \end{align} Similarly, \mu_1(t) = \frac{\sum^{L-1}_{i=t} iP(i)}{\omega_1(t)}.[src] Now, let \sigma^2_0(t) and \sigma^2_1(t) be the (pixel intensity) variance of C_0 and C_1 respectively.[src] \begin{align} \sigma_0^2(t) &= \sum^{t-1}_{i=0} (i - \mu_0)^2 P(i | C_0) = \sum^{t-1}_{i=0} \frac{(i - \mu_0)^2 P(i)}{\omega_0} = \frac{\sum^{t-1}_{i=0} (i - \mu_0)^2P(i)}{\omega_0(t)}.[src] \end{align} Similarly, \sigma_1^2(t) = \frac{\sum^{L-1}_{i=t} (i - \mu_1)^2 P(i)}{\omega_1(t)}.[src] Let, \sigma_b^2(t) be the inter-class (pixel intensity) variance, which is defined as the weighted sum of variances of aforementioned two classes.[src] \begin{align} \sigma^2_b(t) &= \sigma^2_T - \left[\omega_0(t) \sigma^2_0(t) + \omega_1(t) \sigma^2_1(t)\right] \\ &= \omega_0(\mu_0 - \mu_T)^2 + w_1 (\mu_1 - \mu_T)^2 \\ &= \omega_0\omega_1(\mu_0 - \mu_1)^2.[src] \end{align} Where, \sigma^2_T(t) variance of the total histogram.[src] The algorithm is now to maximise \sigma_b^2(t) , i.e.[src] inter-class variance.[src] This standpoint is motivated by a conjecture that well-thresholded classes would be separated in pixel intensities, and conversely a threshold t^* giving the best separation of classes in pixel intensities would be the best threshold.[src] Formally, this problem is summarised as the following.[src] ===Algorithm=== Compute histogram and probabilities of each intensity level.[src] Set up initial \omega_0(0) , \mu_0(0) and \omega_1(0) and \mu_1(0) .[src] Step through all possible thresholds from t = 1 to maximum intensity.[src] Update \omega_0(0) , \mu_0(0) and \omega_1(0) and \mu_1(0) .[src] Compute \sigma^2_b(t) .[src] Desired threshold t^* corresponds to the maximum \sigma^2_b(t) .[src] ===MATLAB implementation=== histogramCounts is a 256-element histogram of a grayscale image different gray-levels (typical for 8-bit images).[src] level is the threshold for the image (double).[src] function level = otsu(histogramCounts) total = sum(histogramCounts); % total number of pixels in the image %% OTSU automatic thresholding top = 256; sumB = 0; wB = 0; maximum = 0.0; sum1 = dot(0:top-1, histogramCounts); for ii = 1:top wB = wB + histogramCounts(ii); wF = total - wB; sumB = sumB + (ii-1) * histogramCounts(ii); if wB > 0 && wF > 0 mF = (sum1 - sumB) / wF; val = wB * wF * ((sumB / wB) - mF) * ((sumB / wB) - mF); if ( val >= maximum ) level = ii; maximum = val; end end end end Matlab has built-in functions graythresh() and multithresh() in the Image Processing Toolbox, which are implemented with Otsu's method and multi-Otsu's method, respectively.[src] import numpy as np def otsu_intraclass_variance(image, threshold): """ Otsu's intra-class variance.[src] If all pixels are above or below the threshold, this will throw a warning that can safely be ignored.[src] """ return np.nansum( [ np.mean(cls) * np.var(image, where=cls) # weight · intra-class variance for cls in [image >= threshold, image Python libraries dedicated to image processing such as OpenCV and Scikit-image provide built-in implementations of the algorithm.[src] ==Limitations and variations== Otsu's method performs well when the histogram has a bimodal distribution with a deep and sharp valley between the two peaks.[src] Like all other global thresholding methods, Otsu's method performs badly in case of heavy noise, small objects size, inhomogeneous lighting and larger intra-class than inter-class variance.[src] In those cases, local adaptations of the Otsu method have been developed.[src] Moreover, the mathematical grounding of Otsu's method models the histogram of the image as a mixture of two normal distributions with equal variance and equal size.[src] However, Otsu's thresholding may yield satisfying results even when these assumptions are not met, in the same way statistical tests (to which Otsu's method is heavily connected ) can perform correctly even when the working assumptions are not fully satisfied.[src] Several variations of Otsu's methods have been proposed to account for more severe deviations from these assumptions, such as the Kittler–Illingworth method.[src] P_{ij} = \frac{f_{ij}}{N}, \qquad \sum_{i=0}^{L-1} \sum_{j=0}^{L-1} P_{ij} = 1.[src] And the 2-dimensional Otsu's method is developed based on the 2-dimensional histogram as follows.[src] The probabilities of two classes can be denoted as \begin{align} \omega_0 &= \sum_{i=0}^{s-1} \sum_{j=0}^{t-1} P_{ij}, \\ \omega_1 &= \sum_{i=s}^{L-1} \sum_{j=t}^{L-1} P_{ij}.[src] \end{align} The intensity mean-value vectors of two classes and total mean vector can be expressed as follows: \begin{align} \mu_0 &= [\mu_{0i}, \mu_{0j}]^T = \left[\sum_{i=0}^{s-1} \sum_{j=0}^{t-1} i \frac{P_{ij}}{\omega_0}, \sum_{i=0}^{s-1}\sum_{j=0}^{t-1} j \frac{P_{ij}}{\omega_0} \right]^T, \\ \mu_1 & =[\mu_{1i}, \mu_{1j}]^T = \left[\sum_{i=s}^{L-1}\sum_{j=t}^{L-1} i \frac{P_{ij}}{\omega_1}, \sum_{i=s}^{L-1}\sum_{j=t}^{L-1} j \frac{P_{ij}}{\omega_1} \right]^T, \\ \mu_T & =[\mu_{Ti}, \mu_{Tj}]^T = \left[\sum_{i=0}^{L-1} \sum_{j=0}^{L-1} i P_{ij}, \sum_{i=0}^{L-1}\sum_{j=0}^{L-1} j P_{ij}\right]^T.[src] \end{align} In most cases the probability off-diagonal will be negligible, so it is easy to verify \omega_0 + \omega_1 \cong 1, \omega_0 \mu_0 + \omega_1 \mu_1 \cong \mu_T.[src] The inter-class discrete matrix is defined as S_b = \sum_{k=0}^1 \omega_k[(\mu_k - \mu_T)(\mu_k - \mu_T)^T].[src] The trace of the discrete matrix can be expressed as \begin{align} \operatorname{tr}(S_b) &= \omega_0[(\mu_{0i} - \mu_{Ti})^2 + (\mu_{0j} - \mu_{Tj})^2] + \omega_1[(\mu_{1i} - \mu_{Ti})^2 + (\mu_{1j} - \mu_{Tj})^2] \\ &= \frac{(\mu_{Ti} \omega_0 - \mu_i)^2 + (\mu_{Tj} \omega_0 - \mu_j)^2}{\omega_0(1 - \omega_0)}, \end{align} where \mu_i = \sum_{i=0}^{s-1} \sum_{j=0}^{t-1} iP_{ij}, \mu_j = \sum_{i=0}^{s-1} \sum_{j=0}^{t-1} jP_{ij}.[src] Similar to one-dimensional Otsu's method, the optimal threshold (s, t) is obtained by maximizing \operatorname{tr}(S_b) .[src] max, s, t = 0; for ss: 0 to L - 1 do for tt: 0 to L - 1 do evaluate tr(S_b); if tr(S_b) > max max = tr(S, b); s = ss; t = tt; end if end for end for return s, t; Notice that for evaluating \operatorname{tr}(S_b) , we can use a fast recursive dynamic programming algorithm to improve time performance.[src] However, even with the dynamic programming approach, 2D Otsu's method still has large time complexity.[src] Therefore, much research has been done to reduce the computation cost.[src] If summed area tables are used to build the 3 tables sum over P_{ij} , sum over i P_{ij} , and sum over j P_{ij} then the runtime complexity is \max\big(O(N_\text{pixels}), O(N_\text{bins}^2)\big) .[src] Note that if only coarse resolution is needed in terms of threshold, N_\text{bins} can be reduced.[src] function threshold = otsu_2D(hists, total) maximum = 0.0; threshold = 0; helperVec = 0:255; mu_t0 = sum(sum(repmat(helperVec',1,256).*hists)); mu_t1 = sum(sum(repmat(helperVec,256,1).*hists)); p_0 = zeros(256); mu_i = p_0; mu_j = p_0; for ii = 1:256 for jj = 1:256 if jj == 1 if ii == 1 p_0(1,1) = hists(1,1); else p_0(ii,1) = p_0(ii-1,1) + hists(ii,1); mu_i(ii,1) = mu_i(ii-1,1)+(ii-1)*hists(ii,1); mu_j(ii,1) = mu_j(ii-1,1); end else p_0(ii,jj) = p_0(ii,jj-1)+p_0(ii-1,jj)-p_0(ii-1,jj-1)+hists(ii,jj); % THERE IS A BUG HERE.[src] INDICES IN MATLAB MUST BE HIGHER THAN 0.[src] ii-1 is not valid mu_i(ii,jj) = mu_i(ii,jj-1)+mu_i(ii-1,jj)-mu_i(ii-1,jj-1)+(ii-1)*hists(ii,jj); mu_j(ii,jj) = mu_j(ii,jj-1)+mu_j(ii-1,jj)-mu_j(ii-1,jj-1)+(jj-1)*hists(ii,jj); end if (p_0(ii,jj) == 0) continue; end if (p_0(ii,jj) == total) break; end tr = ((mu_i(ii,jj)-p_0(ii,jj)*mu_t0)^2 + (mu_j(ii,jj)-p_0(ii,jj)*mu_t1)^2)/(p_0(ii,jj)*(1-p_0(ii,jj))); if ( tr >= maximum ) threshold = ii; maximum = tr; end end end end ==References== ==External links== Implementation of Otsu's thresholding method as GIMP-plugin using Script-Fu (a Scheme-based language) Lecture notes on thresholding – covers the Otsu method A plugin for ImageJ using Otsu's method to do the threshold A full explanation of Otsu's method with a working example and Java implementation Implementation of Otsu's method in ITK Otsu Thresholding in C# – a straightforward C# implementation with explanation Otsu's method using MATLAB Otsu Thresholding with scikit-image in Python[src]

66 sentences · 66 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Otsu's method." encyclopegia.org, 2026, https://encyclopegia.org/wiki/otsu-s-method. Accessed 01 December 2026.

Chicago

"Otsu's method." encyclopegia.org. Accessed December 1, 2026. https://encyclopegia.org/wiki/otsu-s-method.

APA

encyclopegia.org. (2026). Otsu's method. Retrieved December 1, 2026, from https://encyclopegia.org/wiki/otsu-s-method

Accessed December 1, 2026 · CC BY-SA 4.0 · citation page · JSON

CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1342226247 · 0.5 · snapshot enwiki-001342226247

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners
  • Index — every corpus, paper and record
  • Estate guide — what a public data estate is
  • Founder — Lois-Kleinner Alpasan
  • Records — DOIs and external deposits
  • Documents — one-pagers, PDFs and QR codes
  • Brand kit — logos and share images
  • Papers — plain-language briefs with citations
  • Browser — search engine, PWA and bookmarklet
  • Anticloud — the operator and its projects

As seen in Business Insider · 336 outlets · evidence DOIs · plain-language papers

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.