OTSU/Maximum Entropy/Tsallis Image Segmentation and Its GA-optimized MATLAB Implementation

insert image description here
insert image description here

This article is the first part of the image segmentation series. As an introduction part, it mainly discusses three classic image segmentation algorithms: OTSU, maximum entropy, and Tsallis entropy are applied to grayscale image threshold segmentation, using a simple single threshold segmentation, and using genetic algorithm to optimize In the optimization process, since it is a single-threshold and one-dimensional algorithm, only the traversal algorithm can achieve better results. For multi-threshold and two-dimensional and three-dimensional segmentation algorithms, it will continue to be updated in subsequent articles.

00 Article Directory

1 Threshold segmentation algorithm
2 Program catalog
3 Threshold segmentation algorithm combined with genetic algorithm
4 Source code acquisition
5 Outlook

01 Threshold segmentation algorithm

Threshold segmentation technology is widely used because of its simplicity, effectiveness and easy implementation. According to the number of thresholds, the threshold segmentation method can be divided into two-level threshold segmentation and multi-level threshold segmentation. Two-level threshold segmentation is to divide the image area into foreground and background through a single threshold, and to divide the image into multiple areas by setting multiple thresholds is called multi-level threshold segmentation. Multi-threshold segmentation can be considered as an extension of two-level threshold segmentation. How to quickly find the optimal threshold is the key and difficult point of the multi-threshold image segmentation method, and the well-known threshold selection criteria are the maximum between-class variance method and various entropy methods.

1.1 Threshold Segmentation

The threshold-based image segmentation method is a common method for grayscale image segmentation. By setting different grayscale thresholds to classify the grayscale histogram of the image, when the grayscale value of the pixel is within the same grayscale range, the pixel is considered to belong to The same category has certain similarities. Use I(I,j) to represent the gray value of i×j pixels in the image I, the gray range of the image I is divided into L levels on average, and the threshold T is used to divide the pixels in the image I into the target class C0 and the background class C1 two categories, then the image O(ij) after threshold segmentation is:insert image description here

Where: I(I,j) is the input image: i is the row number of the image pixel set; j is the column number of the image pixel set; T is the threshold.
Therefore, choosing an appropriate gray-scale threshold to accurately segment the image is the key to the threshold-based image segmentation method.

1.2 OTSU algorithm

The OTSU algorithm was proposed by the Japanese scholar Nobuyuki Otsu in 1979, also known as the maximum inter-class variance method, which divides the image into two parts, the background and the foreground, according to the grayscale characteristics, and the variance is used as a measure of the uniformity of the grayscale distribution. The larger the value, the greater the difference between the two parts that make up the image, that is, the greater the variance between classes, and any confusion and misclassification will lead to a smaller difference. Therefore, the largest variance between classes means that the probability of misclassification is the smallest, that is, the The two parts in the image are optimally segmented. The grayscale range of image I is divided into L grades on average, and the total number of pixels N is:insert image description here

Ni is the number of pixels in the i-th gray level, and N is the total number of pixels.
Therefore, the probability density distribution Pi of the histogram is:insert image description here

Assume that the threshold T divides the image into two categories, set the target class as C0={T+1, T+2,...L-1}, the background class as C1={0,1,...,T}, and set o 2 as the variance between classes , then the optimal threshold T' satisfies the largest inter-class variance, and the inter-class variance o2 is:insert image description here

Among them: o^2 is the inter-class variance; T' is the threshold with the largest inter-class variance;
OTSU algorithm is the best algorithm for threshold selection in image segmentation, which is not affected by image brightness and contrast and is simple to calculate. However, this method is sensitive to image noise and is only suitable for single target segmentation. When the size ratio of the target and the background differs greatly, or the variance function between classes is bimodal or multimodal, the effect of the algorithm is not good.

1.3 Maximum Entropy (KSW) Algorithm

The principle of the maximum entropy threshold segmentation algorithm is as follows: Let the total number of pixels of the image be M, the gray range G = {0,1,…, L −1 }, the number of pixels with gray value i be mi, and the segmentation threshold be t, t splits the image into two parts, object A and background B. Assuming that the pixels whose gray value is less than the threshold belong to the target A, and the pixels whose gray value is greater than or equal to the threshold belong to the background B, then the probability that the pixels in the image involve the target A and the background B are respectively:insert image description here

The optimal threshold is the maximum value of the entropy sum of the target and background:insert image description here
insert image description here
insert image description here

The total entropy of an image is defined as:insert image description here

When φ (t) reaches the maximum value, the corresponding t value is the segmentation threshold.

1.4 Tsallis entropy algorithm

Tsallis entropy is characterized by high flexibility and adaptability. For an image with gray level G, p; is the probability that gray level i appears in the image. The Tsallis entropy Sq for each distribution is:insert image description here

Among them: q is to use the histogram mean value of the segmented image to select.
In the case of single-threshold segmentation, set the threshold z to divide the image into two types: target A and background B, and the total entropy of Tsallis is: S^A+B_q is:
insert image description here
insert image description here
insert image description here

Among them: wA is the gray probability of target A; wB is the gray probability of background B; SAq(z) is the Tsallis entropy of target A; SBq(z) is the Tsallis entropy of background B; SA+Bq( z) is the total entropy of Tsallis.

It can be seen that the OTSU algorithm is not affected by the brightness and contrast of the image, and the calculation is simple. However, when the variance function between classes may be bimodal or multimodal, this method does not work well. In addition, to improve the anti-noise ability of the OTSU algorithm, two-dimensional or three-dimensional OTSU algorithms can be used, but it will increase the computational complexity, resulting in increased processing time. The entropy algorithm is based on the existing information to infer the unknown information, which has the characteristics of high flexibility, strong adaptability and fast calculation speed. General threshold finding methods include traversal and intelligent algorithms. For one-dimensional single threshold, since there are only 256 thresholds, the traversal method is relatively fast.

02 Program directory

A total of three folders, each storing matlab codes of OTSU, KSW, Tsallis methods and their genetic algorithm optimization methods
insert image description here

For example KSW:insert image description here

Among them, the core code of the KSW method is as followsinsert image description here

The core code of the OTSU method is as follows
insert image description here

The core code of the Tsallis method:
insert image description here

03 Threshold segmentation algorithm combined with genetic algorithm

The principle of the genetic algorithm has been explained in detail in the author's previous articles, and the principle will not be repeated here, but its fitness and coding will be mainly introduced.
The fitness of the genetic algorithm, for OTSU, is the variance between classes, the bigger the better, for KSW and Tsallis, it is the maximum entropy.
The coding of the genetic algorithm, because it is a single-threshold problem, uses binary coding with a total of 8 bits, for example, 00001111, which means the threshold is 1+2+2 2 +2 3=15.

3.1 Dataset

Several common images are used for threshold segmentation experiments, as follows:insert image description here

The corresponding histogram curve is as follows:
insert image description here

3.2 Comparison of Threshold Segmentation Results

insert image description here

Since the threshold segmentation algorithms are all one-dimensional and single-threshold, it only needs to be optimized in 0-255. The results of the traversal method and the genetic algorithm optimization method are obviously similar, because the amount of calculation is small, so the traversal method will also faster. The threshold obtained by the genetic algorithm is not a fixed value, but fluctuates within a certain range. This is because the population of the genetic algorithm is randomly generated, that is, the randomness of the population, so the threshold obtained by the final image segmentation has certain fluctuations. ,This is acceptable. In one-dimensional space, the speed of genetic algorithm is slightly slower, which does not reflect the high speed of genetic algorithm, but in the case of two-dimensional space or multiple thresholds, genetic algorithm will have obvious advantages in speed, which will be discussed in subsequent articles displayed in.
KSW method segmentation display
insert image description here

insert image description hereinsert image description here

04 Source code acquisition

链接:https://pan.baidu.com/s/1NFYiI0FNg5HnPV80GNVcjw?pwd=1111 
提取码:1111

05 Outlook

So far, the one-dimensional single-threshold image segmentation algorithm is introduced here. Although the above-mentioned algorithm has a fast processing speed, its anti-noise ability, segmentation accuracy and robustness are insufficient, so it is necessary to improve it. The author will continue to introduce this aspect in subsequent articles. If you find it helpful, you can also follow a wave of authors, you will not get lost if you follow, and you will not suffer if you follow.

微信公众号:KAU的云实验台

Guess you like

Origin blog.csdn.net/sfejojno/article/details/131363080