# Quadratic Curve Fitting-Based Image Edge Line Segment Detection: A Novel Methodology
## 3 Edge Line Segment Extraction Based on Quadratic Curve Fitting
The pseudocode for implementing the above process is illustrated by Algorithm 1:  
```
Input : Contour \(C_{i}=\left\{(x_{j},y_{j})|j=1,2,3,...,n\right\}\), whose length is n; the current quadratic curve equation coefficients are \(e_{k}\),\(f_{k}\) and \(g_{k}\) Output : Pixel sequence L (L indicates a continuous and the longest pixel sequence);
1 Initialization: Set the variables \(P_{s}=0\) and \(P_{e}\) to store the start and end points of a continuous pixel sequence; set the variable \(Count=0\) for counting consecutive pixels; set the variable Flag = 0 for determining the start of the continuous pixel region; set the variable \(P_{sl}=0\) and the \(P_{el}=0\) as the starting point and the ending point for storing L, respectively; and set \(Count_{l}=0\) as the pixels number of L; and setting the quadratic curve fitting error \(\varepsilon\)
2 forEach pixel point \((x_{i},y_{i})\)do
3 Combine \((x_{i},y_{i})\) bring into Equation (10) to calculate E;
4 ifE is less than the set \(\varepsilon\)then
5 Variables Count Add 1
6 ifFlag = 0 then
7\(P_{s}\) set to the current position \((x_{i},y_{i})\)
8 end if
9\(P_{e}\) set to the current position \((x_{i},y_{i})\), Flag set to 1;
10 else
11\(Flag\) set to 0, \(Count\) set to 0;
12
13 end if
14 ifCount is greater than \(Count_{l}\)then
15\(P_{sl}\) set to \(P_{s}\), \(P_{el}\) set to \(P_{e}\)
16\(Count_{1}\) set to \(Count\). 17
18 end if
19
20 end for
21 Based on \(P_{sl}\),\(P_{el}\) and \(Count_{l}\) determine \(L\). ```  
**Algorithm 1**The search algorithm for L when \(\varepsilon_{k}\),\(f_{k}\) and \(g_{k}\) are determined. Step 3: In Step 2, it is necessary to randomly select three non-collinear pixels from the edge contour set \(C_{i}=\left\{(x_{j},y_{j})|j=1,2,3,...,n\right\}\). Therefore, pixel selection needs to  
Figure 1: Edge contour containing multiple edge line segments. be performed three times randomly. If there are a total of n pixels in the edge contour set \(C_{i}\), and if the pixel length of one of the longest image sequences is denoted as L with a length of \(len(L)\), then the probability that the selected pixels exactly fall on sequence L in a single random selection is (\(\dfrac{len(L)}{n}\)). The probability that all three randomly selected pixels consecutively fall on sequence L is \(\left(\dfrac{len(L)}{n}\right)^{3}\). The probability that none of the three sampled pixels fall on sequence L is  
\[P=1-\left(\dfrac{len(L)}{n}\right)^{3} \tag{11}\]  
In this algorithm, a threshold is set such that the probability of not selecting sequence L after K repeated samplings is less than 1%. If we want to obtain L in the set, it is necessary to repeat Step 2 K times, and the number of repetitions K is determined as follows:  
\[P^{K}<0.01\Rightarrow K>ceil\left(\dfrac{\lg 0.01}{\lg P}\right) \tag{12}\]  
The function ceil(\(\bullet\)) represents rounding up to the nearest integer. Therefore, as long as the number of iterations K is greater than the value in Equation (12), it is possible to reliably search for L in \(C_{i}\). Furthermore, we define \(D_{i}\) to store the continuous and longest edge segments. This means that the sequence L obtained from \(C_{i}\) in Step 3 is added to the collection \(D_{i}\) as an edge segment. After K iterations, if no L is found, \(D_{i}\) remains empty, indicating that there are no satisfying edge segments in \(C_{i}\). Step 4: After finding an edge line segment L in \(C_{i}\), L is removed from \(C_{i}\) and the remaining pixels form a new edge profile stored in R. Due to the three different distributions of L in the set \(C_{i}\), deleting L corresponds to three different cases, as shown in Figure 2. The pseudocode for implementing the above process is illustrated by Algorithm 2:  
Figure 2: The distribution position of \(C_{i}\) is in L. (**a**) The starting pixel of L, \(n_{1}\), is located at the initial position of set \(C_{i}\), and the ending pixel, \(n_{2}\), is located at the middle position of set \(C_{i}\).