# A Line Segment Detector for Space Target Images Robust to Complex Illumination
## 2 Methods
### Anchor Map Extraction Method Combined with Improved Otsu
By using the trace of \(\sigma_{B}\) as the measurement of between-class variance, there is:  
\[Tr(\sigma_{B})=\omega_{b}\bigg{[}(\delta_{bi}-\delta_{Li})^{2}+\left(\delta_{bj}- \delta_{Lj}\right)^{2}\bigg{]}+\omega_{o}\Big{[}(\delta_{oi}-\delta_{Li})^{2}+ \left(\delta_{oj}-\delta_{Lj}\right)^{2}\Big{]} \tag{13}\]  
Therefore, the optimal threshold pair \(s^{*},t^{*}\) can be obtained by maximizing the between-class variance:  
\[P_{ij}=\frac{n_{ij}}{M\times N} \tag{6}\]0  
We propose a construction strategy for a two-dimensional histogram. Based on the fact that median filtering can suppress salt-and-pepper noise well, the steps of median filtering are introduced in the construction of a two-dimensional histogram. Firstly, the original image \(f\) is median filtered with \(k\times k\) convolution kernel, and median image \(M\) can be expressed as:  
\[M(x,y)=med\Bigg{\{} \begin{array}{c}f(\widetilde{x},\widetilde{y})\Big{|}x- \frac{k-1}{2}\leq\widetilde{x}\leq x+\frac{k-1}{2},\\ y-\frac{k-1}{2}\leq\widetilde{y}\leq y+\frac{k-1}{2}\end{array} \Bigg{\}} \tag{15}\]  
Secondly, according to the obtained median image \(M\), the corresponding mean image can be calculated by:  
\[A(x,y)=\sum_{\widetilde{x}=x-(k-1)/2}^{x+(k-1)/2}\sum_{\widetilde{y}=y-(k-1)/ 2}^{y+(k-1)/2}M(\widetilde{x},\widetilde{y}) \tag{16}\]  
Finally, we use the median image \(M\) and the mean image \(A\) to construct a two-dimensional histogram. Based on constructing a two-dimensional gray histogram, the inter-class variance is calculated, and the optimal segmentation threshold is obtained by maximizing the interclass variance. The flow chart is shown in Figure 4. Algorithm 1 shows the implementation process of the improved two-dimensional Otsu algorithm. ```
Input: The gray image \(f\); Initialization parameter. Output: Otsu segmentation result image \(O\). Step1: median filtering. Step2: construct the 2D histogram using median image \(M\) and median-average image \(A\). Step3: calculate the between-class variance \(Tr\). for\(i=0\) to \(256\)do for\(j=0\) to \(256\)do \(Tr\leftarrow\left(\omega_{b}(\delta_{Li}-\delta_{bi})^{2}\right)+\left(\omega_ {o}\Big{(}\delta_{lj}-\delta_{oj}\Big{)}^{2}\right)/(\omega_{b}\omega_{o})\)  Step4: calculate the optimal threshold for maximizing the between-class variance. if(\(Tr>\)maxvariance)then  maxvariance\(\leftarrow\)Trthreshold\(\_s\gets i\)  threshold\(\_t\gets j\)  end if  end for \(T\leftarrow\)threshold\(\_s\) return\(T\)  Step5: segment the image by the threshold value \(T\). ShowImage \(O\). ```  
**Algorithm 1** Improved Otsu method The improved Otsu method is used to process the image, then the gradient magnitude and gradient orientation are calculated, and the effective anchors are extracted in two steps. Firstly, we use the non-maximum suppression method of the Canny algorithm to extract pixels to obtain general anchors. Secondly, based on the property that the gradient direction of line pixel should be aligned with neighbor pixels. To improve the effectiveness of anchor points and simplify the anchor map, we further verify the general anchors by the orientation and extract general pixels aligned with their neighbor edge pixels as effective anchors. Algorithm 2 presents the implementation process of the anchor map extraction method combined with Otsu. ```
Input: The image \(I\) processed by the improved Otsu method;  the gradient orientation tolerance \(\mu\). Output: Effective anchors \(A_{e}\). Step1: calculate the gradient magnitude \(G_{m}\) and gradient orientation \(G_{o}\) of pixel \(P(x,y)\); the center pixel of the neighborhood of pixel \(P(x,y)\) is \(G_{p}\); the interpolation of two gradient amplitudes along the gradient orientation is \(G_{p1}\) and \(G_{p2}\), respectively; output the general anchors \(A_{g}\). if\(G_{p}\geq G_{p1}\) and \(G_{p}\geq G_{p2}\)then \(A_{g}\gets G_{p}\) else \(G_{p}\gets 0\) endif return\(A_{g}\)  Step2: verify the general anchors and obtain effective anchors \(A_{e}\); the gradient orientation of the general anchors \(A_{g}\) is \(G_{g}\).