Thresholding (image processing): Difference between revisions

Content deleted Content added
Major re-organisation of the article as I thought it was a bit of a mess. In particular, redefinition of what "automatic threshold" is. I'll create a topic in the Talk page to explain more.
Line 1:
{{short description|Image segmentation algorithm}}
[[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|ExampleThe ofbinary aimage thresholdresulting effectfrom useda onthresholding anof 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|(Shapiro, et al. 2001:83)]]</ref>
Line 6:
==Definition==
 
The simplest thresholding methods replace each pixel in an image with a black pixel if the image intensity <math>I_{i,j}</math> is less than somea fixed constantvalue Tcalled the (that is,threshold <math>I_{i,j}<T</math>), or a white pixel if the imagepixel intensity is greater than that constantthreshold. In the example image on the right, this results in the dark tree becoming completely black, and the whitebright snow becoming completely white.
 
==CategorizingAutomatic thresholding methods==
 
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 it should separate in two classes the brighter objects considered to be part of the foreground and the darker objects considered to be part of the background.
To make thresholding completely automated, it is necessary for the computer to automatically select the threshold T. Sezgin and Sankur (2004) categorize thresholding methods into the following six groups based on the information the algorithm manipulates [[#Sezgin2004|(Sezgin et al., 2004)]]:
 
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)]] categorizes thresholding methods into broad groups based on the information the algorithm manipulates. 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
* '''Clustering'''-based methods, where the gray-level samples are clustered in two parts as background and foreground (object), or alternately are modeled as a mixture of two Gaussians
* '''[[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|last1=Zhang|first1=Y.|title=Optimal multi-level Thresholding based on Maximum Tsallis Entropy via an Artificial Bee Colony Approach|journal=Entropy|date=2011|volume=13|issue=4|pages=841–859|doi=10.3390/e13040841|bibcode=2011Entrp..13..841Z|doi-access=free}}</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 [that] use higher-order probability distribution and/or correlation between pixels
* '''Local''' methods adapt the threshold value on each pixel to the local image characteristics. In these methods, a different T is selected for each pixel in the image. The T can be of many types like mean, gaussian, median, mode(not used generally).
 
* '''[[Histogram]] shape'''-based methods, where, for example, the peaks, valleys and curvatures of the smoothed histogram are analyzed<ref>{{Cite journal |last=Zack |first=G W |last2=Rogers |first2=W E |last3=Latt |first3=S A |date=1977-07 |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 |issn=0022-1554}}</ref>. Note that these methods, more than others, make certain assumptions about the image intensity probability distribution (i.e., the shape of the histogram),
==Multiband thresholding==
* '''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 |last=Barghout |first=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–709 |doi=10.1167/13.9.709 |issn=1534-7362}}</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>{{citeCite journal |last1last=ZhangKapur |first1first=YJ. N. |titlelast2=OptimalSahoo multi|first2=P. K. |last3=Wong |first3=A. K. C. |date=1985-level03-01 Thresholding|title=A basednew onmethod Maximumfor Tsallisgray-level Entropypicture viathresholding anusing Artificialthe Beeentropy Colonyof the histogram |url=https://www.sciencedirect.com/science/article/pii/0734189X85901252 Approach|journal=EntropyComputer Vision, Graphics, and Image Processing |datelanguage=2011en |volume=1329 |issue=43 |pages=841–859273–285 |doi=10.33901016/e130408410734-189X(85)90125-2 |bibcodeissn=2011Entrp..13..841Z|doi0734-access=free189X}}</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 [that] use higher-order probability distribution and/or correlation between pixels.
Colour 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 colour. Therefore, the [[HSL and HSV]] colour 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]] colour model [[#Pham2007|(Pham et al., 2007)]].
 
[[File:Example of adaptive thresholding.png|thumb|418x418px|Example of the advantage of local thresholding in the case of inhomogeneous lighting. Image adapted from [https://docs.opencv.org/3.4/d7/d4d/tutorial_py_thresholding.html].]]
== Probability distributions ==
 
==Multiband= Global vs local thresholding ===
Histogram shape-based methods in particular, but also many other thresholding algorithms, make certain assumptions about the image intensity probability distribution. The most common thresholding methods work on bimodal distributions, but algorithms have also been developed for [[Unimodal thresholding|unimodal distributions]], multimodal distributions, and [[Circular thresholding|circular distributions]].
In most methods, the same threshold is applied to all the pixel 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 information 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 |last=Wayne. |first=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}}</ref> or the Bernsen algorithms.
 
== Automatic thresholding ==
Automatic thresholding is a great way to extract useful information encoded into pixels while minimizing background noise. This is accomplished by utilizing a feedback loop to optimize the threshold value before converting the original grayscale image to binary. The idea is to separate the image into two parts; the background and foreground.<ref>{{Cite book|title=Digital Image Processing and Analysis with MATLAB and CVIPtools, Third Edition|last=E.|first=Umbaugh, Scott|isbn=9781498766074|edition=3rd|oclc=1016899766|date = 2017-11-30}}</ref>
 
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].
# Select initial threshold value, typically the mean 8-bit value of the original image.
# Divide the original image into two portions;
## Pixel values that are less than or equal to the threshold; background
## Pixel values greater than the threshold; foreground
# Find the average mean values of the two new images
# Calculate the new threshold by averaging the two means.
# If the difference between the previous threshold value and the new threshold value are below a specified limit, you are finished. Otherwise apply the new threshold to the original image keep trying.
 
==Extensions Automaticof thresholdingbinary thresholding==
 
=== Multi-band images ===
=== Note about limits and threshold selection ===
ColourColor 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 colourcolor. Therefore, the [[HSL and HSV]] colourcolor 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]] colourcolor model<ref>{{Cite journal [[#Pham2007|(last=Pham et|first=Nhu-An al|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=PMC1810239 |pmid=17326824}}</ref>.
The limit mentioned above is user definable. A larger limit will allow a greater difference between successive threshold values. Advantages of this can be quicker execution but with a less clear boundary between background and foreground. Picking starting thresholds is often done by taking the mean value of the grayscale image. However, it is also possible to pick out the starting threshold values based on the two well separated peaks of the image histogram and finding the average pixel value of those points. This can allow the algorithm to converge faster; allowing a much smaller limit to be chosen.
 
=== MethodMultiple limitationsthresholds ===
Instead of a single threshold resulting in a binary image, it is also possible to introduce multiple increasing thresholds <math>T_n</math>. In that case, implementing <math>N</math> thresholds will result in an image with <math>N</math> classes, where pixels with intensity <math>I_{ij}</math> such that <math>T_n < I_{ij} < T_{n+1}</math> will be assigned to class <math>n</math>. Most of the binary automatic thresholding methods have a natural extension for multi-thresholding.
Automatic thresholding will work best when a good background to foreground contrast ratio exists. Meaning the picture must be taken in good lighting conditions with minimal glare.
 
== See alsoLimitations ==
Thresholding will work best under certain conditions :
*[[Otsu's method]]
 
*[[Balanced histogram thresholding]]
* low level of noise
* higher intra-class variance than inter-class variance, i.e., pixels from a same group have closer intensities to each other than to pixels of another group,
* homogeneous lighting, etc.
 
In difficult cases, thresholding will likely be imperfect and yield a binary image with [[false positives and false negatives]].
 
==References==