# Glass Defect Detection with Improved Data Augmentation under Total Reflection Lighting
## 3 Principle and Improvement of Defect Detection Algorithm
### Data Augmentation and Improvement
#### 3.4.3 Image Fusion  
Image fusion involves segmenting the target area in an image to seamlessly integrate it into a new image, meeting the demands of data augmentation. Image fusion primarily consists of two processes: segmenting the target area and post-image fusion. Utilizing entropy segmentation as discussed earlier enables the effective extraction of defective images and the generation of defect masks. Common image fusion methods include PCA-based fusion, logical filtering, neural networks, and weighted averaging, among others. In this fusion process, a method based on Poisson editing [30] is employed to merge the target defect and clean background into a new image. By utilizing gradient information from the background image and defect image, along with the boundary distribution information of the defect image, a new pixel distribution is constructed for the fused image using interpolation. In the synthesized image, the background image size is specified as 480 \(\times\) 480 and the final synthesized image size is also the same, ensuring that all images are of a uniform standard size for their input into network models for training. As represented in Figure 15, S, a closed subset on the two-dimensional image \(R^{2}\), represents the image domain. \(\Omega\) is a closed subset on S with the boundary \(\partial\Omega\). \(f^{*}\) is a known scalar function defined on S, and g is a known scalar function defined on \(\Omega\). Then we minus \(\Omega\) inside, make \(f\) an unknown scalar function defined inside of \(\Omega\), and finally make \(v\) a vector field defined on \(\Omega\). Figure 14: Extracted defects. Figure 15: Schematic diagram of Poisson image editing. The essence of Poisson image editing is to introduce gradient \(v\) to conduct module interpolation and minimize the difference between the gradient field and the target gradient field, so as to solve the unknown scalar function \(f\). \[\min_{f}\ =\ \iint\alpha|\
abla f-v|^{2},f|_{\partial\Omega}=f^{*}|_{\partial\Omega} \tag{13}\]  
With the formula \(\
abla=\left[\frac{\partial}{\partial x},\frac{\partial}{\partial y}\right]\). Formula (14) has a unique solution to [PERSON]'s equation with a Dirichlet boundary condition, as follows:  
\[\
abla f=div\ v,\ f|_{\partial\Omega}=f^{*}|_{\partial\Omega} \tag{14}\]  
\(\Delta=\frac{\partial^{2}}{\partial x}+\frac{\partial^{2}}{\partial y}\) is the Laplace operator, \(div\ v\) is the divergence of \(v=(u,\ v)\), and \(div\ v=\frac{\partial_{u}}{\partial x}+\frac{\partial_{v}}{\partial y}\). As for discretizing images, the underlying discrete pixel grid can discretize the problem naturally. Based on that, a finite difference discretization of (14) produces Equation (12). For \(p\in\partial\Omega\), there is  
\[\min_{f\cap\ \Omega}\sum_{p,q\cap\Omega\
eq 0}\left(f_{p}-f_{q}-v_{pq}\right)^{2 },f_{p}=f_{q}^{*} \tag{15}\]  
\(p\) is the pixel point on \(S\). \(N_{p}\) is a collection of its four N. \(v_{pq}\) represents the projection of \(\
u\left(\frac{p+q}{2}\right)\) onto \([p,q]\). The solution of \(v_{pq}=\
u\left(\frac{p+q}{2}\right)\cdot pq\) satisfies the following linear equation:  
\[\big{|}N_{p}\big{|}f_{p}-\sum_{q\in N_{p}\cap\Omega}f_{q}=\sum_{q\in N_{p}\cap \Omega}f_{q}^{*}+\sum_{q\in N_{p}}v_{pq} \tag{16}\]  
For \(p\in\partial\Omega\) pixels located inside \(\Omega\), there is no boundary condition term on the right of Equation (13), which can be simplified as:  
\[\big{|}N_{p}\big{|}f_{p}-\sum_{q\in N_{p}\cap\Omega}f_{q}=+\sum_{q\in N_{p}}v _{pq} \tag{17}\]  
The result of the fusion is shown in Figure 16.  
Figure 16: Image fusion. During the fusion process, the positions of the defects in the background image are randomly selected. The upper left vertex of the maximum circumscribed rectangle of defects is defined as \(Z_{\max}(x,y)\), the lower right vertex is defined as \(Z_{min}(x,y)\), and the position information of the background image is \(B_{max}(x,y)\), \(B_{min}(x,y)\).