## 2 Methodology
### Shape Searching Algorithm Based on Edge Gradient Direction  
The shape of the image is outlined by the edge, and the edge is the location of gray level changes. The edge also corresponds to the boundary between the foreground and the background. Therefore, the edge gradient direction information can also reflect the shape of the image to some extent [28; 29]. In general, the regular contour and obvious shape have a regular histogram of the edge gradient direction. Otherwise, the histogram of the edge gradient direction appears random. Therefore, the shape can be described on the basis of the histogram of the edge gradient direction, which is a suitable shape description method. The calculation steps of the histogram of the edge gradient direction are as follows. First, the edge gradient of the shape is calculated using the Sobel gradient operator shown in Formulas (2) and (3), where \(w_{1}\) is the horizontal gradient operator and \(w_{2}\) is the vertical gradient operator:  
\[\mathbf{w}_{1}=\left[ \begin{array}{ccc}-1&0&1\\ -2&0&2\\ -1&0&1\end{array} \right] \tag{2}\]  
Figure 7: Experimental results of shape searching algorithm based on contour point distribution information. (**a**) Shape 1; (**b**) Shape 2. \[\mathbf{w}_{2}=\left[ \begin{array}{ccc}-1&-2&-1\\ 0&0&0\\ 1&2&1\end{array} \right] \tag{3}\]  
Second, with the assumption that the image corresponding to the shape region is \(I(i,j)\), the gradient along the x direction is its horizontal gradient denoted by \(G_{x}(i,j)\), which is given in Formula (4). Here, \(i,j\), respectively, denote the horizontal and vertical position of the convolution calculation center at the time of Sobel extraction. The calculation is performed on the image corresponding to the minimum circumscribed rectangle of each shape region. \[ \begin{array}{rl}G_{x}(i,j)=&\left[I(i-1,j+1)+2*I(i,j+1)+I(i+1,j+1)-I(i-1,j-1 )-2*I(i,j-1)\right.\\ &\left.-I(i+1,j-1)\right],\ 0<i<m,\ 0<j<n\end{array}  \tag{4}\]  
Third, the gradient along the y direction, i.e., the vertical gradient is denoted by \(Gy(i,j)\), which is given in Formula (5):  
\[ \begin{array}{rl}G_{y}(i,j)=&\left[I(i+1,j-1)+2*I(i+1,j)+I(i+1,j+1)-I(i-1,j- 1)-2*I(i-1,j)\right.\\ &\left.-I(i+1,j+1)\right],\ 0<i<m,\ 0<j<n\end{array}  \tag{5}\]  
Therefore, the gradient direction is given in Formula (6):  
\[\theta=\arctan(\frac{G_{y}(i,j)}{G_{x}(i,j)})\ 0\leq\theta<2\pi \tag{6}\]  
where angle \(\theta\) is quantized every \(5^{\circ}\) as a direction. Thus, the interval between \(0\) and \(2\pi\) is divided into \(72\) direction bins. The histogram of the edge gradient direction can be obtained by counting the number of edge points in each direction. Figure 8 illustrates the histogram of the edge gradient direction, in which every \(5^{\circ}\) is a column. Variables \(L\) and \(H_{g}\) represent the edge perimeter of a shape and the histogram of the edge gradient direction for storing the number of edge points in each direction. These two variables are given in Formula (7). Parameter \(h_{\rm i}\) represents the number of edge points in the i-th gradient direction of each shape region. Figure 8: Histogram of edge gradient direction for the shape region. (**a**) Schematic diagram of gradient direction. (**b**) Histogram of gradient direction of one shape region  
\[\left\{ \begin{array}{l}H_{\text{g}}=(h_{1},h_{2},\ldots,h_{72})\\ \sum\limits_{i=1}^{72}h_{i}=L\end{array} \right. \tag{7}\]  
As shown in Figure 9, several differently shaped regions (marked as green portions) and the corresponding histograms of their edge gradient directions are given. The shape shown in Figure 9a is particularly close to a rectangle. Figure 9b shows that the edge gradient direction of the shape is mainly concentrated in the horizontal and vertical directions, that is, \(\pi/2\), \(\pi\), \(3\pi/2\), and \(2\pi\). The four directions respectively correspond to 18, 36, 54, and 72 gradient direction bins. The histogram of the edge gradient direction distribution resembles a cross shape and a quasi-cross shape. Figure 9c shows an elliptical shape.