Some simple implementations of image segmentation

zhaozj2021-02-17  73

Research on Automatic Selection of Thresholds in Image Segmentation and Its Algorithm Implementation

Image split is the basic problem in this discipline, and the threshold-based segmentation is one of the most basic problems of image segmentation, and its difficulty is the selection of the threshold. It turns out that the appropriateness of the threshold will play a decisive role in the effect of the segmentation. Since the threshold segmentation is selected for image segmentation, this paper is mainly based on [1], [2], [3], [4], etc., and has explored, implement and compare some currently popular threshold selection algorithms. Multi-threshold segmentation can further improve the quality of image segmentation, but because it is only the processing of segmentation skills, it is different from the single-threshold segmentation. Therefore, this article does not discuss multi-threshold segmentation, while only considering a single threshold segmentation.

1. Double peak method

The principle of the double peak method and its simple: it believes that the image consists of the foreground and background, on the grayscale histogram, both the front and rear two views form a peak, the minimum valley between the bispan is the threshold of the image. According to this principle, we give its implementation, some code is as follows (Pascal language description, the following):

// INTPEAK, INTPEAK2, INTVALLEY: peak and histogram value

// intindx :: Corresponding gray value

INTPEAK, INTINDX, INTPEAK2, INTINDX2, INTVALLEY, INTVALLEYINDX: Integer;

// initial double peak

INTPEAK: = 0;

INTPEAK2: = 0;

// get the first peak value

For intloop: = 0 to 255 DO

IF INTPEAK <= intgraylelevel [INTLOOP] THEN

Begin

INTPEAK: = INTGRAYLEVEL [INTLOOP];

INTINDX: = INTLOOP;

END;

/ / Get the second peak

For intloop: = 0 to 255 DO

Begin

IF (INTLOOP2 <= Intgraylelevel [INTLOOP]) and (intloop <> intindx) THEN

Begin

INTPEAK2: = INTGRAYLEVEL [INTLOOP];

INTINDX2: = INTLOOP;

end

END;

/ / Get the valley between the double peaks

INTVALLEY: = INTSIZE;

IF intindx2

For intloop: = intindx2 to intindx do

IF IntValley> Intgraylevel [Intloop] THEN

Begin

INTVALLEY: = Intgracylevel [INTLOOP];

INTVALLEYINDX: = INTLOOP;

END;

From the perspective of segmentation, the comparison of the current background is more strong, and the segmentation effect is better; otherwise it is basically invalid.

2. Iterative method

The iterative method is based on approximation, and its steps are as follows:

1. The maximum gray value and minimum gradation value of the image are obtained, respectively, respectively, to make the initial threshold T0 = (Zmax Zmin) / 2;

2. According to the threshold TK, the image is divided into prospects and background, and the average grayscale ZO and ZB of the two are obtained, respectively;

3. Ask new threshold TK 1 = (ZO ZB) / 2;

4. If TK = TK 1, the result is a threshold; otherwise the transfer 2, iterative calculations.

The following part of the threshold is given below:

// Threshold initial 0

intTHRESHOLDVAL: = 0;

INTTHRESHOLDVAL2: = 0; // Total grayscale value

INTTTOALGRAYLVEL: = 0;

For intloop: = 0 to 255 DO

IF Intgraylevel [Intloop] <> 0 THEN

INTTOTALGRAYLVEL: = INTTOTALGRAYLEVEL INTLOOP * INTGRAYLEVEL [INTLOOP];

/ / Find the initial maximum gray value

For intloop: = 0 to 255 DO

IF Intgraylevel [Intloop]> 0 THEN

Begin

INTLGRAYLVEL: = INTLOOP;

IntethResholdVal: = INTLOOP;

Break;

END;

/ / Find out the initial minimum gray value and initial threshold

For intloop: = 255 DOWNTO 0 DO

IF Intgraylevel [Intloop]> 0 THEN

Begin

INTRGRAYLVEL: = INTLOOP;

IntethresholdVal: = (intTTHRESHOLDVAL INTLOOP) DIV 2;

Break;

END;

// Iterative Solution

While IntethresholdVal <> intTHRESHOLDVAL2 DO

Begin

INTTHRESHOLDVAL2: = intTHRESHOLDVAL;

INTCOUNT: = 0;

INTLGRAYLVEL: = 0;

For intloop: = 0 to intTHRESHOLDVAL DO

IF Intgraylevel [Intloop] <> 0 THEN

Begin

INTCOUNT: = INTCOUNT INTGRAYLVEL [INTLOOP];

INTLGRAYLVEL: = INTLGRAYLVEL INTLOOP * INTGRAYLVEL [INTLOOP];

END;

INTRGRAYLVEL: = INTTTOALGRAYLEVEL-INTLGRAYLVEL;

INTLGRAYLVEL: = INTLGRAYLVEL DIV INTCOUNT

INTRGRAYLVEL: = IntrGrayLevel Div (INTSIZE-INTCOUNT);

INTTHRESHOLDVAL: = (INTLGRAYLEVEL IntrGrayLevel) DIV 2;

END;

The image effect of the threshold division of iteration is good. The iterative threshold can distinguish between the foreground and the main area of ​​the image and the main area of ​​the background, but in the subtleties of the image (such as the light colored lines in Figure 1) have no good distractions.

Surprisingly, the changes in certain specific images, micro data can cause huge changes in segmentation, but the data is only slightly changed, but the segmentation effect is very large, and the medium in the middle is still to be further the study.

3. Dajin Law (OTSU)

The Dajin Law was proposed by Tajin in 1979. The image image, the screwdrive threshold of the foreground, the foreground point number is W0, the average grayscale U0; the background point number is the ratio of W1, the average grayscale U1 . The total average gradation of the image is: u = W0 * U0 W1 * U1. From the minimum gradation value to the maximum gray value, T, when t is made, the value G = W0 * (U0-U) 2 W1 * (U1-U) 2 is maximum T is the optimal threshold of the divided. It can be understood as follows: This form is actually a difference between the inter-class side partial difference, the foreground and the background of the threshold T-divided, and the background of the foreground, and the probability is W0, the background value U1, The probability is W1, the total average is u, and the definition is defined according to the variance. Because variance is a measure of the uniformity of grayscale distribution, the larger the variance, the larger the difference between the two parts constituting the image, and when some target misses are background or partial background faults, the differences can cause two parts to become small. Therefore, the maximum segmentation between the variance between the class is meant to be the least missed. Direct application of the gravidity is large, so we use equivalent formula G = W0 * W1 * (U0-U1) 2 when implementing. Partial computing process is as follows:

// Traverse all grayscale values ​​MAX G.

For intCurrentlevel: = 0 to INTARRLEN DO

Begin

IF INTSCLGRAYLVEL [INTCURRENTLEVEL] = 0 THEN

Continue

Else

Begin

/ / Calculate G of the threshold is Intcurrentlevel

INTCOUNT: = 0;

INTSUMPELS: = 0;

For intloop: = 0 to intCurrentlevel DO

Begin

INTCOUNT: = INTCOUNT INTSCLGRAYLEVEL [INTLOOP];

INTSUMPELS: = INTSUMPELS INTSUMPELSARR [INTLOOP];

END;

W0: = INTCOUNT / INTSIZE

U0: = INTSUMPELS / INTCOUNT

W1: = 1-w0;

IF INTSIZE-INTCOUNT <> 0 THEN

U1: = (inttotalpels-intesumpels) / (INTSIZE-INTCOUNT)

Else

U1: = 0;

RLTEMPO: = W0 * W1 * (U0-U1) * (U0-U1);

IF rltempo> rlmaxo then

Begin

RLMAXO: = rltempo;

Result: = INTCURRENTLEVEL;

END;

END;

We found in the test: The thresholds selected by the Dajin Law are ideal, and the performance of various situations is better. Although it is not the best segmentation in many cases, the segmentation quality usually has a certain guarantee, which can be said to be the most stable segmentation. It is known that the Dajin Algorithm is a more general segmentation algorithm. Under its idea, people further propose a variety of similar evaluation thresholds, specific to [5], [6], etc.

4. Grayscale stretching - an improved Dajin Law

The Dajin Law has been widely used, but some people have found that the defects of the Great Law are not obvious when the target and the background gradation are not obvious, and the unbearable large black area will even lose the entire image. In order to solve this problem, some people have proposed a grayscale stretching. The principle of this method is actually to enhance the grayscale difference between the front background by increasing the gradation of the grayscale, so as to solve the problem. The method of increasing the grayscale is to multiply the same coefficient with the original gray level, and the gradation of the grayscale, in particular, when the coefficient is one is 1, this is the prototype of the Dajin Law, therefore It can be seen as a special case of this method. In the implementation, we implemented a variety of grayscale stretching, discovering different images, and when meeting different tensile coefficients, the segmentation effect is far from the difference.

5. Kirsh operator

In [4], the segmentation method based on the Kirsh operator is proposed. The idea is: each pixel I of the digital image, considering the grayscale value of the eight adjacent points, with three adjacent points of adjacent points and Leave the weighting and get the difference in the remaining five outpoints, so that the three neighters are constantly displaced by the pixel point, and the maximum value of this eight differences is taken as the Kirsh operator. That is, the Si is the sum of Si, Ti is the sum of the five adjacent points, then the kirsh operator is defined as k (i) = max {1, Max [5Si-3Ti]} If the threshold THK is taken, when K ( i)> THK, pixel i is a step edge point. In addition, the author of [4] believes that it is assumed that the image size is H × W pixel point, and its edge point pixels generally do not exceed 5 × H. Based on this fake, the author puts forward: (for an image) with a kirsh algorithm, take a lower initial threshold THK (to ensure that the image edge of the grayscale change in the target and the background can be taken out), For each pixel point i, its kirsh operator is calculated. If K (i)> ThK, i is the edge point, the edge point N (the initial value is 0) plus 1, once the number of edge points exceeds 5 × h, and I is less than The number of pixels of the whole image, indicating that the threshold is too low, causing a number of pixels that are not the edge point to be removed, so the threshold is required. Things are repeated, the threshold required to split the image can be obtained.

However, in the implementation, the authors found that the narrative in [4] is worth exploring. In the H × W image, the relationship between H and W is completely symmetrical, how to choose between the two? In addition, there is quite doubts about Kirsh operator K (i) = max {1, MAX [5Si-3Ti]}, which is not obvious that the resulting image effect is not obvious. Based on symmetry and normalization, the author changed the kirsh operator to: k (i) = max {1, Max ABS (5SI-3TI) Div 15}, and based on the effect in actual operation, W and H'S: IF W> H Then USE 5 * H Else USE 5 * W. In practical applications, the modified segmentation quality is significantly improved. However, compared with the effects claimed in the [4], there is still a considerable distance, especially if it does not solve the split situation in the previous rear. However, the current background contrast is very strong and concentrated, the kirsh operator method will have a very prominent manifestation. references

[1] Cui Wei, Digital Image Processing Technology and Application, Electronic Industry Press, 1997

[2] Fu Zhongliang, image threshold selection method, computer application, 2000

[3] Wu Bing, Qin Zhiyuan, automatically determine the new method of image binaryization optimal threshold, Journal of School of Drawing, 2000

[4] Cao Lihua, an image edge extraction, a dynamic threshold acquisition method, a small microcomputer system, 1997 [5] Fu Zhongliang, the threshold selection method, computer research and development based on image gap metric, 2001

[6] Fu Zhongliang, some new image threshold selection method, computer application, 2001

[7] Kenneth.r.castleman, Zhu Zigang et al, digital image processing, electronic industrial publishing house, 1998

转载请注明原文地址:https://www.9cbs.com/read-31366.html

New Post(0)