# Target Image Mask Correction Based on Skeleton Divergence
## 2 Materials and Methods
### Mask Optimization Based on Skeleton Divergence
The larger the \(\sigma_{r}\), the greater the effect of the angle difference. This study uses the same weight factor settings as [20]: \(\sigma_{d}=4.5,\sigma_{r}=2.5\). With this new set of scale-invariant intrinsic variables, a set of vertex-coordinate linear equations is then established to recover the smooth image edge vector. The process of solving the vertex-coordinate linear equations may provide no solution. Suppose the curve after smoothing is \(C^{*}\), its vertex is \(v_{i}^{*}\left(x_{i}^{*},y_{i}^{*}\right)\), and its scale-invariant intrinsic variables are expressed as  
\[\Omega^{*}{=\{(\tau_{i}^{*},\theta_{i}^{*})\}_{i=1}^{n-1}}. \tag{4}\]  
The relationship between the adjacent sides \(\overline{v_{i+1}^{*}v_{i}^{*}}\), \(\overline{v_{i}^{*}v_{i-1}^{*}}\) of the common vertex \(v_{i}^{*}\) is  
\[\overline{v_{i+1}^{*}v_{i}^{*}}=r_{i}^{*}R\left(\overline{\theta_{i}^{*}} \right)\overline{v_{i}^{*}v_{i-1}^{*}}. \tag{5}\]  
Among them,  
\[R\left(\theta_{i}^{*}\right)=\left( \begin{array}{cc}\cos\theta_{i}^{*}&-\sin \theta_{i}^{*}\\ \sin\theta_{i}^{*}&\cos\theta_{i}^{*}\end{array} \right). \tag{6}\]  
Then Equation (5) can be rewritten as  
\[\left( \begin{array}{c}x_{i+1}^{*}-x_{i}^{*}\\ y_{i+1}^{*}-y_{i}^{*}\end{array} \right)=r_{i}^{*}\left( \begin{array}{cc}\cos \theta_{i}^{*}&-\sin\theta_{i}^{*}\\ \sin\theta_{i}^{*}&\cos\theta_{i}^{*}\end{array} \right)\left( \begin{array}{ c}x_{i}^{*}-x_{i-1}^{*}\\ y_{i}^{*}-y_{i-1}^{*}\end{array} \right). \tag{7}\]Equation (7) is a set of two linear equations for the vertex coordinates \(x_{i-1}^{*},y_{i-1}^{*},x_{i}^{*},y_{i}^{*},x_{i+1}^{*},y_{i+1}^{*}\), according to the vertex subscripts \(\mathrm{i}=1,2,\cdots,\mathrm{n}-1\) in sequence, a linear system of equations can be obtained:  
\[\Upsilon\mathrm{Z}=0, \tag{8}\]  
where \(\Upsilon\) is a matrix of order \((2n-2)\times(2n+2)\), \(\mathrm{Z}\) is a vector consisting of all vertex coordinates of curve \(\mathrm{C}^{*}\). \(\mathrm{Z}=\left(x_{0}^{*},y_{0}^{*}x_{1}^{*},y_{1}^{*},\cdots,x_{n-1}^{*},y_ {n-1}^{*},x_{n}^{*},y_{n}^{*}\right)^{T}\), as can be seen from the literature [20], the matrix \(\Upsilon\) is a row full-rank matrix, its rank is 2n-1. In this study, the coordinates of two vertices \(v_{x},v_{y}\) are set in advance as the benchmark for mask correction, that is, the coordinates of the two vertices of \(v_{x}^{*}\), \(v_{y}^{*}\) are the same as \(v_{x},v_{y}\), respectively. Substituting the coordinates of the two points into the linear Equation (5), a new system of linear equations can be obtained:  
\[\overline{\Upsilon}\mathrm{Z}=b_{0}, \tag{9}\]  
where \(\overline{\Upsilon}\) is a sparse matrix of \((2n+2)\times(2n+2)\) orders, and \(b_{0}\) is a \((2n+2)\) dimensional column vector. Since \(\overline{\Upsilon}\) is a full-rank square matrix, the solution of the linear Equation (6) is unique, and the vertex coordinate set of the curve \(\mathrm{C}^{*}\) after smoothing is obtained. Using the smoothed edge vector set, the image skeleton is then extracted simultaneously from the source and mask images, and skeleton processing proceeds using Delaunay triangulation [16]. The skeleton is then used as the center for local mask correction and localized area merging with edge guidance, for simultaneous optimization of source and mask images. Similar to the method in [20], in this study, the skeleton extraction is divided into three steps, which are briefly described as follows. 1. Delaunay triangulation is performed on the polygons enclosed by the obtained boundary vertices, and the Voronoi diagram is obtained at the same time. 2. The watershed algorithm is used to detect the raised points on the boundary. 3. With the obtained dual map and raised point information, part of the triangular piece is deleted according to the principle of homotopy equivalence, and the final approximate skeleton is obtained. As the pixel grayscale gradient and edge guidance information near the skeleton exhibit similar gradients, the effect of edge guidance is optimized while reducing the required search area.