# Segmentation of Stone Slab Cracks Based on an Improved YOLOv8 Algorithm
## 2 Improved YOLOv8 Segmentation Network
### Dynamic Snake Convolution Detection Head  
Since pixels in input images are limited, and cracks in stone slabs occupy a small part of the image, the model has difficulty in extracting subtle feature changes [34; 35]. Also, the complex and changeable structure of cracks leads to poor detection performance and low recognition efficiency. Inspired by deformable convolution, as shown in Figure 6, the model  
Figure 4: Sample-based dynamic upsampling. Figure 5: DySample’s point sampling generator: (**a**) static range factor; (**b**) dynamic range factor. adjusts the shape of convolutional kernels during feature learning to focus on the basic structural features of cracks. However, considering the small proportion of core structural features of cracks and the risk of convolutional kernels deviating from the crack area, we introduce the dynamic snake convolution [36] detection head. This module can effectively extract key features in stone slab crack segmentation under restricted conditions without deviating from the target structure. Dynamic snake convolution extracts local crack features through the following process. For a standard 2D convolution, a \(3\times 3\) kernel is defined over fixed coordinates. It can be represented as follows:  
\[S=\{(x-1,y-1),(x,y-1),\dots(x+1,y+1)\} \tag{6}\]  
\(S\) denotes the ordered \(3\times 3\) regular sampling grid centered on the reference pixel; \(x\) and \(y\) are the integer spatial coordinates of that reference pixel in the input feature map. To enhance the convolutional kernel's ability to capture irregular crack patterns, deformable parameters \(\Delta\) are introduced for the geometric adaptation of the receptive field. Without proper regularization, data-driven learning of offsets may cause the receptive field to drift away from the actual spatial distribution of cracks. To address this, an iterative strategy shown in Figure 7a is adopted. It sequentially aligns each target with observable positions, maintaining focused attention and preventing excessive expansion of the receptive area. In dynamic snake convolution, the standard kernel is stretched along the \(x\) and \(y\) axes. A \(9\times 9\) kernel is used. For the \(x\)-axis, each position \(S_{i}\) is computed as (\(x_{i\pm c}\), \(y_{i\pm c}\)), where {0, 1, 2, 3, 4} represents the horizontal offset from the center grid. The position selection within the kernel follows an accumulative process. Starting from the center,  
Figure 6: (**a**) Ordinary convolution; (**b**) dilation convolution; (**c**) deformable convolution; and (**d**) dynamic snake convolution. Figure 7: (**a**) Dynamic snake convolution computation process; (**b**) dynamic snake convolution sensory field. each subsequent position increases by one and adds an offset. The accumulated offset \(\Sigma\) ensures the alignment of the kernel with the morphological structure of cracks in stone slabs. Variations along the \(x\) and \(y\) axes are computed separately. \[S_{i\pm c}=\left\{ \begin{array}{l}(x_{i+c},y_{i+c})=(x_{i}+c,y_{i}+\sum_{j}^{ i+c}\Delta y)\\ (x_{i-c},y_{i-c})=(x_{i}-c,y_{i}+\sum_{i-c}^{i}\Delta y)\end{array} \right. \tag{7}\]  
\[S_{j\pm c}=\left\{ \begin{array}{l}(x_{j+c},y_{j+c})=(x_{j}+\sum_{j}^{i+c} \Delta x,y_{i}+c)\\ (x_{j-c},y_{j-c})=(x_{j}+\sum_{j-c}^{j}\Delta x,y_{i}-c)\end{array} \right. \tag{8}\]  
Compared to \(S_{i+1}\), \(S_{i}\) introduces an additional offset \(\Delta=\{\delta\,\mathrm{1}\,\delta\in[-1,\,1]\}\). This offset must be accumulated across stages. Since \(\Delta\) is typically small and coordinates are integers, bilinear interpolation is applied to maintain spatial accuracy, formulated as follows:  
\[S=\sum_{y}Bi(S^{\prime},S)\cdot S^{\prime} \tag{9}\]  
\[Bi(S,S^{\prime})=bi(S_{x},S^{\prime}_{x})\cdot bi(S_{y},S^{\prime}_{y}) \tag{10}\]  
As shown in Figure 7b, DSConv covers a \(9\times 9\) region through deformation along both the \(x\) and \(y\) axes, effectively expanding the receptive field. This dynamic adaptation better aligns with the morphological characteristics of stone slab cracks.