[[Image:Pavlovsk Railing of bridge Yellow palace Winter.jpg|thumb|250px|Original image.]][[Image:Pavlovsk Railing of bridge Yellow palace Winter bw threshold.jpg|thumb|250px|The binary image resulting from a thresholding of the original image.]]
In [[digital image processing]], '''thresholding''' is the simplest method of [[image segmentation|segmenting images]]. From a [[grayscale]] image, thresholding can be used to create [[binary image]]s.<ref>[[#Shapiro2001{{cite book |(last1=Shapiro, et|first1=Linda alG. |last2=Stockman |first2=George C. |title=Computer Vision |date=2001: |publisher=Prentice Hall |isbn=978-0-13-030796-5 |page=83)]] }}</ref>
==Definition==
==Automatic thresholding==
While in some cases, the threshold <math>T</math> can or should be selected manually by the user, there are many cases where the user wants the threshold to be automatically set by an algorithm. In those cases, the threshold should be the "best" threshold in the sense that itthe partition of the pixels above and below the threshold should separatematch inas twoclosely classesas possible the brighteractual objectspartition consideredbetween tothe betwo partclasses of objects represented by those pixels (e.g., pixels below the foregroundthreshold andshould correspond to the darkerbackground objectsand consideredthose above to besome partobjects of interest in the backgroundimage).
Many types of automatic thresholding methods exist, the most famous and widely used being [[Otsu's method]]. The following list, based on the works of [[#Sezgin2004|Sezgin et al. (2004)]] categorizescategorized thresholding methods into broad groups based on the information the algorithm manipulates.<ref>{{cite journal |last1=Sankur |first1=Bülent |title=Survey over image thresholding techniques and quantitative performance evaluation |journal=Journal of Electronic Imaging |date=2004 |volume=13 |issue=1 |pages=146 |doi=10.1117/1.1631315 |bibcode=2004JEI....13..146S }}</ref> Note however that such a categorization is necessarily fuzzy as some methods can fall in several categories (for example, Otsu's method can be both considered a histogram-shape and a clustering algorithm).
* '''[[Histogram]] shape'''-based methods, where, for example, the peaks, valleys and curvatures of the smoothed histogram are analyzed.<ref>{{Cite journal |lastlast1=Zack |firstfirst1=G W |last2=Rogers |first2=W E |last3=Latt |first3=S A |date=July 1977 |title=Automatic measurement of sister chromatid exchange frequency. |url=http://journals.sagepub.com/doi/10.1177/25.7.70454 |journal=Journal of Histochemistry & Cytochemistry |language=en |volume=25 |issue=7 |pages=741–753 |doi=10.1177/25.7.70454 |issnpmid=002270454 |s2cid=15339151 |doi-1554access=free }}</ref> Note that these methods, more than others, make certain assumptions about the image intensity probability distribution (i.e., the shape of the histogram),
* '''Clustering'''-based methods, where the gray-level samples are clustered in two parts as background and foreground,<ref>{{Cite journal |date=1978 |title=Picture Thresholding Using an Iterative Selection Method |url=http://ieeexplore.ieee.org/document/4310039/ |journal=IEEE Transactions on Systems, Man, and Cybernetics |volume=8 |issue=8 |pages=630–632 |doi=10.1109/TSMC.1978.4310039 |issn=0018-9472}}</ref><ref>{{Cite journal |lastlast1=Barghout |firstfirst1=L. |last2=Sheynin |first2=J. |date=2013-07-25 |title=Real-world scene perception and perceptual organization: Lessons from Computer Vision |url=http://jov.arvojournals.org/Article.aspx?doi=10.1167/13.9.709 |journal=Journal of Vision |language=en |volume=13 |issue=9 |pages=709–709709 |doi=10.1167/13.9.709 |issn=1534doi-7362access=free }}</ref>
* '''[[Entropy (information theory)|Entropy]]'''-based methods result in algorithms that use the entropy of the foreground and background regions, the cross-entropy between the original and binarized image, etc.,<ref>{{Cite journal |lastlast1=Kapur |firstfirst1=J. N. |last2=Sahoo |first2=P. K. |last3=Wong |first3=A. K. C. |date=1985-03-01 |title=A new method for gray-level picture thresholding using the entropy of the histogram |url=https://www.sciencedirect.com/science/article/pii/0734189X85901252 |journal=Computer Vision, Graphics, and Image Processing |language=en |volume=29 |issue=3 |pages=273–285 |doi=10.1016/0734-189X(85)90125-2 |issn=0734-189X}}</ref>
* '''Object Attribute'''-based methods search a measure of similarity between the gray-level and the binarized images, such as fuzzy shape similarity, edge coincidence, etc.,
* '''Spatial''' methods use higher-order probability distribution and/or correlation between pixels.
=== Global vs local thresholding ===
In most methods, the same threshold is applied to all the pixelpixels of an image. However, in some cases, it can be advantageous to apply a different threshold to different parts of the image, based on the local informationvalue of the pixels. This category of methods is called local or adaptive thresholding. They are particularly adapted to cases where images have inhomogeneous lighting, such as in the sudoku image on the right. In those cases, a user-defined neighborhood is defined and a threshold is computed for each pixel and its neighborhood. Many global thresholding methods can be adapted to work in a local way, but there are also methods developed specifically for local thresholding, such as the Niblack<ref>{{Cite book |first=Wayne |last=Niblack |url=http://worldcat.org/oclc/1244113797 |title=An introduction to digital image processing |date=1986 |publisher=Prentice-Hall International |isbn=0-13-480600-X |oclc=1244113797 }}{{pn|date=April 2024}}</ref> or the Bernsen algorithms.
Software such as [[ImageJ]] propose a wide range of automatic threshold methods, both [https://imagej.net/plugins/auto-threshold global] and [https://imagej.net/plugins/auto-local-threshold local].
=== Benefits of Local Thresholding Over Global Thresholding<ref>Zhou, Huiyu., Wu, Jiahua., Zhang, Jianguo. Digital Image Processing: Part II. United States: Ventus Publishing, 2010.{{pn|date=April 2024}}</ref> ===
* Adaptability to Local Image Characteristics: Local thresholding can adapt to variations in illumination, contrast, and texture within different parts of the image. This adaptability helps in handling images with non-uniform lighting conditions or complex textures.
* Preservation of Local Details: By applying tailored thresholds to different regions, local thresholding can preserve fine details and edges that might be lost in global thresholding, especially in areas with varying intensities or gradients.
* Reduced Sensitivity to Noise: Local thresholding can be less sensitive to noise compared to global thresholding, as the thresholding decision is based on local statistics rather than the entire image.
=== Examples of Algorithms for Local Thresholding ===
* Niblack's Method:<ref>{{Cite book |first=Wayne |last=Niblack |title=An introduction to digital image processing |date=1986 |publisher=Prentice-Hall International |isbn=0-13-480600-X |oclc=1244113797 |pages=115-116 }}</ref> Niblack's algorithm computes a local threshold for each pixel based on the mean and standard deviation of the pixel's neighborhood. It adjusts the threshold based on the local characteristics of the image, making it suitable for handling variations in illumination.
* Bernsen's Method:<ref>Chaki, Nabendu., Shaikh, Soharab Hossain., Saeed, Khalid. Exploring Image Binarization Techniques. Germany: Springer India, 2014.{{pn|date=April 2024}}</ref> Bernsen's algorithm calculates the threshold for each pixel by considering the local contrast within a neighborhood. It uses a fixed window size and is robust to noise and variations in background intensity.
* Sauvola's Method:<ref>{{cite journal |last1=Sauvola |first1=J. |last2=Pietikäinen |first2=M. |title=Adaptive document image binarization |journal=Pattern Recognition |date=February 2000 |volume=33 |issue=2 |pages=225–236 |doi=10.1016/S0031-3203(99)00055-2 |bibcode=2000PatRe..33..225S }}</ref> Sauvola's algorithm extends Niblack's method by incorporating a dynamic factor that adapts the threshold based on the local contrast and mean intensity. This adaptive factor improves the binarization results, particularly in regions with varying contrasts.
==Extensions of binary thresholding==
=== Multi-band images ===
Color images can also be thresholded. One approach is to designate a separate threshold for each of the [[RGB color model|RGB]] components of the image and then combine them with an [[Binary and|AND]] operation. This reflects the way the camera works and how the data is stored in the computer, but it does not correspond to the way that people recognize color. Therefore, the [[HSL and HSV]] color models are more often used; note that since [[hue]] is a circular quantity it requires [[circular thresholding]]. It is also possible to use the [[CMYK color model|CMYK]] color model.<ref>{{Cite journal |lastlast1=Pham |firstfirst1=Nhu-An |last2=Morrison |first2=Andrew |last3=Schwock |first3=Joerg |last4=Aviel-Ronen |first4=Sarit |last5=Iakovlev |first5=Vladimir |last6=Tsao |first6=Ming-Sound |last7=Ho |first7=James |last8=Hedley |first8=David W. |date=2007-02-27 |title=Quantitative image analysis of immunohistochemical stains using a CMYK color model |url=https://doi.org/10.1186/1746-1596-2-8 |journal=Diagnostic Pathology |volume=2 |issue=1 |pages=8 |doi=10.1186/1746-1596-2-8 |issn=1746-1596 |pmc=1810239 |pmid=17326824 |doi-access=free }}</ref>
=== Multiple thresholds ===
==References==
{{Reflist}}
==Sources==
*<cite id=Pham2007> Pham N, Morrison A, Schwock J et al. (2007). Quantitative image analysis of immunohistochemical stains using a CMYK color model. [http://www.pubmedcentral.nih.gov/articlerender.fcgi?tool=pubmed&pubmedid=17326824 ''Diagn Pathol.'' '''2:'''8].</cite>
*<cite id=Shapiro2001> [[Linda Shapiro|Shapiro, Linda G.]] & Stockman, George C. (2002). "Computer Vision". Prentice Hall. {{ISBN|0-13-030796-3}}</cite>
*<cite id=Sezgin2004> Mehmet Sezgin and Bulent Sankur, Survey over image thresholding techniques and quantitative performance evaluation, Journal of Electronic Imaging 13(1), 146–165 (January 2004). {{doi|10.1117/1.1631315}}</cite>
==Further reading==
*Gonzalez, Rafael C. & Woods, Richard E. (2002). Thresholding. In Digital Image Processing, pp. 595–611. Pearson Education. {{ISBN|81-7808-629-8}}
*M. Luessi,{{cite M.journal |last1=Eichmann, G. M. Schuster, and A. K. Katsaggelos,|first1=Marco |title=Framework for efficient optimal multilevel image thresholding, |journal=Journal of Electronic Imaging, vol.|date=2009 |volume=18, pp. 013004+,|issue=1 2009.|pages=013004–013004–10 {{doi|doi=10.1117/1.3073891 |bibcode=2009JEI....18a3004L }}
*Y.K. Lai,{{cite P.L.journal |last1=Rosin, |first1=Paul L. |title=Efficient Circular Thresholding, |journal=IEEE Trans.Transactions on Image Processing |date=March 2014 |volume=23( |issue=3), pp. 992–1001|pages=992–1001 (2014). {{doi|doi=10.1109/TIP.2013.2297014 |pmid=24464614 |bibcode=2014ITIP...23..992Y |url=https://orca.cardiff.ac.uk/id/eprint/61181/ }}
*Scott E. Umbaugh (2018). Digital Image Processing and Analysis, pp 93–96. CRC Press. {{ISBN|978-1-4987-6602-9}}
|