Image binarization algorithm

I. Introduction

Image Binarization is the process of setting the grayscale value of the pixels on the image to 0 or 255, which is the process of presenting the entire image with an obvious black and white effect. A binary image has only two values ​​for each pixel: either pure black or pure white. There are many ways to perform binarization, and the most commonly used method is to use the threshold method (Thresholding) for binarization.
According to different threshold selection methods, it can be divided into global threshold and local threshold.

insert image description here

Second, the global threshold (Global Method)

Global thresholding refers to selecting the same threshold for every pixel in the entire image.

1. OTSU algorithm

Otsu method (OTSU) is an algorithm for determining the threshold value of image binarization segmentation, which was proposed by Japanese scholar Otsu in 1979. From the principle of the Otsu method, this method is also called the maximum inter-class variance method, because after the image binarization is performed according to the threshold obtained by the Otsu method, the inter-class variance between the foreground and background images is the largest.

The basic idea of ​​OTSU is: first convert the image into a grayscale image, and divide the image into two parts: background (greater than the threshold) and target (less than the threshold) according to the grayscale characteristics of the image. The greater the inter-class variance between the background and the target, the greater the difference between the two parts that make up the image. When part of the target is misclassified as the background or part of the background is misclassified as the target, the difference between the two parts will become smaller. Therefore, the segmentation that maximizes the variance between classes means that the probability of misclassification is the smallest, and OTSU realizes the selection of the optimal threshold by maximizing the variance between classes.

Application: It is the best method to calculate the global threshold value of the image. The application is self-evident, and it is suitable for most occasions where the global threshold value of the image is required.

Advantages: The calculation is simple and fast, and it is not affected by the brightness and contrast of the image.

Disadvantages: sensitive to image noise; can only be segmented for a single target; when the size ratio of the target and the background is very different, and the variance function between classes may show bimodal or multimodal, the effect is not good at this time.

Detailed Algorithm

3. Local Threshold (Local Method)

Local Method is also called Adaptive Thresholding.
The local threshold method assumes that the illumination received by the image in a certain area is relatively close. It uses a sliding window to scan the image, and compares the brightness of the center point of the sliding window with the brightness of other areas (called neighborhood areas) in the sliding window. If the center point brightness is higher than the neighborhood brightness, the center point is marked as white, otherwise it is marked as black.
Local thresholding is widely used, especially for black and white processing. Many of the algorithms for optical character recognition (OCR) and QR code scanning use local thresholding operations.

1. Sauvola algorithm

Assuming that the coordinates of the current pixel point are (x, y), the area centered on this point is r*r, and g(x, y) represents the gray value at (x, y). The steps of the Sauvola algorithm are:

  1. Calculate the gray mean m(x,y) and standard deviation s(x,y) in the r*r neighborhood
    insert image description here
  2. Calculate the threshold T(x,y) of the pixel point (x,y)
    insert image description here
    or
    insert image description here
    where R is half of the pixel depth of the image, such as 8bit or 256 gray levels, and R=128

2. niblack algorithm

insert image description here

The disadvantages of using the Niblack method are:

Since the image needs to be traversed using the domain r×r template, the threshold value cannot be obtained within the pixel range of the boundary area (r-1)/2; at the same time, when performing image traversal, if the domain r×r range is all background, after NIBLACK After calculation, a part must be determined as the target, resulting in pseudo noise.

In short, when using the Niblack method for image segmentation, the choice of the size of the selected processing template window R*R is very critical. If the selected space is too small, the effect of noise suppression is not ideal, the target subject is not prominent enough, and the selected space is too large. Target details are removed and information is lost.

3. Wolf-jolion algorithm (do not understand)

insert image description here

Note:

K in the algorithm is a hyperparameter, with a value between 0 and 1.
The threshold calculation of these adaptive algorithms focuses on the mean value, and then considers the discrete situation of the distribution of pixel values. The
larger the k, the greater the influence of fluctuations in pixel values ​​(such as standard deviation, extreme values ​​of certain quantities) (making the threshold rising influence). For example, Niblack and Sauvola algorithms, k represents the influence of standard deviation

Guess you like

Origin blog.csdn.net/Mouer__/article/details/127211920