Image segmentation
One of the main tasks of image processing and analysis is segmentation, i.e. dividing an image into areas for which a certain uniformity criterion is met, for example, highlighting areas of approximately the same brightness in an image. The concept of the image area is used to define a coherent group of image elements that have a certain common feature (property).
One of the basic and simple ways is to build a segmentation using a threshold. A threshold is a feature (property) that helps to divide the desired signal into classes. The threshold separation operation is to compare the brightness value of each pixel of the image with the specified threshold value.

Binarization
The threshold split operation, which results in a binary image, is called binarization. The purpose of the binarization operation is to drastically reduce the amount of information contained in the image. In the process of binarization, the original halftone image, which has a certain number of brightness levels, is converted into a black and white image, the pixels of which have only two values - 0 and 1
Threshold image processing can be done in different ways.
')
Binarization with a lower threshold
Binarization with a lower thresholdLower threshold binarization is the simplest operation that uses only one threshold value:

All values instead of the criterion become 1, in this case 255 (white) and all values (amplitudes) of pixels that are greater than the threshold t - 0 (black).
Binarization with upper thresholdSometimes you can use a variant of the first method, which gives a negative image obtained in the process of binarization. Binarization operation with a high threshold:
Dual restriction binarizationTo highlight areas in which the brightness values of the pixels can vary in a known range, binarization is introduced with a double limit (t
1 <t
2 ):

Other variations with thresholds are also possible, where only part of the data is passed (medium band-pass filter).
Incomplete threshold processingThis transformation provides an image that may be easier for further analysis, as it becomes devoid of background with all the details present in the original image.
Multi-level threshold conversionThis operation forms an image that is not binary, but consisting of segments with different brightness.

As for binarization, in fact, everything. Although you can add that there is a global one that is used for the entire image and there is also a local one that captures a part of the picture (image).
Local Thresholding
Ots methodThe method uses a histogram of the distribution of pixel brightness values of the raster image. The histogram is constructed from the values of p
i = n
i / N, where N is the total number of pixels in the image, n
i is the number of pixels with brightness level i. The brightness range is divided into two classes using the threshold brightness level k, k is an integer value from 0 to L. Each class corresponds to the relative frequency ω
0 ω
1 :

Average levels for each of the two image classes:
Next, the maximum value of the evaluation of the quality of the division of the image into two parts is calculated:
where (σ
CL ) 2 = ω
0 ω
1 (μ
1 -μ
0 )
2 is the interclass dispersion, and (σ
total )
2 is the total dispersion for the entire image.
Threshold determination based on image brightness gradientSuppose that the analyzed image can be divided into two classes - objects and background. The algorithm for calculating the threshold value consists of the following 2 steps:
1. The brightness gradient module is determined for each pixel.
Images

2. Calculation of the threshold:
Method of using histogram entropyThe method has acquired its various forms of description and possible variations. Distribution of the total mass of thresholds for a certain amount using various laws and forms of distribution.
Global Threshold Processing
Burnsen method1. A usual square aperture with an odd number of pixels runs in a loop over all pixels of the original image. At each step is Min and Max.
2. The average value Avg = (Min + Max) / 2 is found.
3. If the current pixel is greater than Avg <E - it becomes white, otherwise - black. E - a certain constant set by the user.
4. If the average is less than the contrast threshold, then the current pixel becomes the color that was set by the parameter “color of a doubtful pixel”.
It has several disadvantages: after processing monotonous regions of brightness, strong parasitic interference is formed, in some cases leads to the appearance of false black spots
Aikvil MethodOne of the most productive methods is the Aikvel method. It is often used to process sharp and sharp images. According to this method, the image is processed using two concentric windows: small - S, and large L. Usually, the window shape is assumed to be square. Both windows are sequentially from left to right from top to bottom superimposed on the image in increments equal to the side of the small window S. For window L, the threshold B is calculated so as to divide the pixels into two clusters. If the mathematical expectations of the brightness level in two clusters have a difference exceeding some user-defined level / μ
1 -μ
2 / ≥l, then all pixels inside window S are binarized according to the threshold T. Otherwise, the brightness of pixels from window S is replaced by some close value.
Niblack methodThe idea of this method is to vary the threshold of brightness B binarization from point to point based on the local value of the standard deviation. The brightness threshold at the point (x, y) is calculated as:

where μ (x, y) is the mean and s (x, y) is the standard deviation of the sample for a certain neighborhood of the point. The size of the neighborhood should be minimal, but such as to preserve the local details of the image. At the same time, the size should be large enough to reduce the effect of noise on the result. The value of k determines which part of the object's boundary to take as the object itself. The value of k = -0.2 sets a fairly good separation of objects, if they are black, and the value of k = + 0.2, if the objects are white.
Method Janowitz and BrooksteinThe potential surface is used as the threshold surface for binarization, which is constructed on the basis of local maximization of the brightness gradient. The brightness gradient value is often calculated using the contour operator Sobel or Canny. The image is filtered in order to obtain contour lines of 1 pixel thickness, and then using a 3 × 3 averaging filter. The potential surface, now, is built on an iterative interpolating scheme. The calculation of the surface is in order, starting from the contour pixels. For each non-contour pixel, the interpolation remainder R (x, y) is calculated and the new pixel value P (x, y) at the n + 1-th step must be calculated in accordance with the formulas:

β within 1≤β≤2 for fast convergence.
Total
What I found happily laid out to you, in the future, if it works out and there will be time, I will try to implement part of the algorithms. This is only a small part of everything that exists today, but I am glad to share this.
Thanks for attention.