# A Deep Learning-Based Algorithm for Ceramic Product Defect Detection
## 2 Materials and Methods
### Adaptive Canny Edge Detection Algorithm  
For the input images of ceramic products, precise bounding box coordinates output by the YOLOv10s model are first utilized to accurately define the defect regions within the images as ROIs. By focusing the processing scope and avoiding interference from irrelevant regions, the computational load of subsequent edge detection algorithms is significantly reduced, thereby improving overall processing efficiency. After accurately locating the ROIs, advanced edge detection techniques are employed to capture and localize defect edges with high precision, which aids in in-depth analysis of defect causes and optimization of production processes. The Canny edge detection algorithm is a classic in the field of image processing, designed to accurately identify edge regions where pixel values undergo significant changes. The algorithm integrates steps such as Gaussian filtering, gradient calculation, non-maximum suppression, double-threshold processing, and edge linking to achieve high-precision and reliable detection of image edges. With its high-precision edge localization capability, it can accurately capture the edges of tiny crack defects on the ceramic surface, providing high-quality edge information for subsequent analysis. It boasts excellent noise-resistance performance. By employing Gaussian filtering, it effectively suppresses the noise introduced by the ceramic's complex textures and lighting variations, ensuring the stability of the detection process. During processing, it can form continuous and clear edge lines, clearly presenting the trend and shape of the defects, which aids in precise defect analysis. Additionally, the Canny algorithm has relatively high computational efficiency. It can quickly process a large number of ceramic images, meeting the speed requirements for actual production-level inspection. However, the fixed nature of threshold setting in the  
Figure 5: Network architecture of the improved PSA module. traditional Canny algorithm, which relies on manually adjusted low and high thresholds, limits its adaptive capability across different image scenarios. To overcome this limitation, this study proposes an adaptive Canny edge detection algorithm that analyzes the image's grayscale histogram to find the threshold that maximizes inter-class variance and automatically determines the most suitable low and high thresholds. \[w_{1}(t)=\sum_{i=0}^{t}p_{i} \tag{1}\]  
\[w_{2}(t)=\sum_{i=t+1}^{L-1}p_{i} \tag{2}\]  
\[\mu_{1}(t)=\sum_{i=0}^{t}\frac{ip_{i}}{w_{1}(t)} \tag{3}\]  
\[\mu_{2}(t)=\sum_{i=t+1}^{L-1}\frac{ip_{i}}{w_{2}(t)} \tag{4}\]  
\[\mu=\sum_{i=0}^{L-1}ip_{i} \tag{5}\]  
\[\sigma_{B}^{2}(t)=w_{1}(t)w_{2}(t)[\mu_{1}(t)-\mu_{2}(t)]^{2} \tag{6}\]  
In the adaptive threshold calculation method, it is assumed that the gray level of the image is \(L\), the number of pixels with gray value \(i\) is \(n_{i}\), and the total number of pixels in the image is \(N=\sum_{i=0}^{L-1}n_{i}\). Then a pixel with gray value \(i\) appears with probability \(p_{i}=\frac{n_{i}}{N}\). Setting the threshold value to \(t\), the pixel probabilities of the foreground and background of the image are shown in Equations (1) and (2), respectively. The average gray levels of the foreground and background are shown in Equations (3) and (4), respectively. The average gray level of the whole image is shown in Equation (5). The between-class variance is shown in Equation (6). The adaptive threshold calculation method calculates the between-class variance \(\sigma_{B}^{2}(t)\) by traversing all possible threshold values \(t\) and selects the threshold value \(t*\) that maximizes \(\sigma_{B}^{2}(t)\) as the best threshold value. As illustrated in Figure 6, the complete process of the Adaptive Canny Edge Detection Algorithm is shown. First, the input image undergoes Gaussian filtering to effectively reduce noise interference by smoothing the image.