Basic thresholding
In this section, we will focus on the simplest thresholding - deciding between two classes using a grayscale image. Basic methods use the histogram of the entire image, i.e. this is \textbf{global} thresholding.
A trivial way is to determine the threshold manually (by looking at the histogram). Of course, with overlapping histograms, the task is not so trivial, the threshold can be found by trial and error, or interactively.
If we want to automate the procedure, we can use the following iterative algorithm [1]:
- Select an initial guess for the global threshold \(T\)
- Let's divide the points of the image \((x,y)\) into two groups \(G_1, G_2\), depending on whether their value is greater than the threshold, i.e. whether \(f(x,y,)>T\)
- Let's calculate the average (mean) values for the groups \(G_1, G_2\) and denote them \(m_1, m_2\)
- Let's calculate a new threshold value in the middle between \(m_1\) and \(m_2\) as \[T=\frac{1}{2}(m_1 +m_2)\]
- Repeat steps 2 to 4 until the difference between consecutive T values is less than a predefined value
When the image has \(L\) brightness levels and dimensions \(M, N\) then we calculate \(m_1, m_2\) as:
\[m_1 (T)=\frac{1}{P_1 (T)}\sum_{i=0}^T i p_i \]
\[m_2 (T)=\frac{1}{P_2 (T)}\sum_{i=T+1}^{L-1} i p_i \]
where
\[P_1(T)=\sum_{i=0}^T p_i\]
\[P_2(T)=\sum_{i=T+1}^{L-1} p_i\]
\[p_i=\frac{n_i}{M N}\]
where \(n_i\) is the number of points with brightness level \(i\).
References
[1] Gonzalez, R., C., Woods, E., W., Digital Image Processing, Global Edition, 4th edition, Pearson 2018, ISBN 10: 1-292-22304-9
The PDF version of this text is available here: segmentation_basic_tresholding_eng.pdf