## 2 Theoretical Background and Proposed Method
### Morphological Reconstruction  
Mathematical morphology originated from the geometric study of the permeability of porous media by French scholars in the 1960s. It was initially confined to the geometrical analysis of binary images, but slowly expanded to the field of grayscale and color images. Mathematically, it is based on set theory, integral geometry, and mesh algebra. It has gradually developed into a powerful image analysis technology, widely used in the field of industrial nondestructive testing [16; 17]. Mathematical morphology detects images through a small set called structuring element, and its basic operations include dilation and erosion. From this as the basis, other transformations are made through combinations. Reconstruction of mathematical morphology involves two images, one called a mask image and the other called a marker image, with the latter being smaller than or equal to its corresponding mask image. Reconstruction transformation is an iterative process in which the marker image is used to reconstruct the mask image. The operation process begins with dilating the marker image using 3 \(\times\) 3 all one-square structuring elements, and the dilation result is compared to the mask image point by point and the ones with the lower value are taken as the intermediate result. This intermediate result then replaces the marker image to start another round of dilation and point-by-point comparison with the mask image, and similarly, the ones with the lower value are taken as the intermediate result. This iteration continues until the intermediate result changes no more, and this intermediate result is taken as the final reconstruction result. Let \(m(x,y)\) represent the marker image,\(f(x,y)\) represent the mask image, and \(R\) represent the reconstruction process. Then, the morphological reconstruction operation can be expressed as:  
\[f_{R}(x,y)=R_{f(x,y)}[m(x,y)] \tag{5}\]  
where \(f_{R}(x,y)\) is the result of the reconstruction operation. Reconstruction operation attempts to restore the mask image \(f(x,y)\) using the marker image \(m(x,y)\), and the light regions on \(m(x,y)\) that have completely disappeared will not be restored in \(f_{R}(x,y)\), but light regions partially shown in \(m(x,y)\) are fully recovered in \(f_{R}(x,y)\). The result of reconstruction operation, with the image in Figure 3d as the marker image \(m(x,y)\) and the image in Figure 2d as the mask image \(f(x,y)\), is as shown in Figure 4. It can be seen that the defect region is completely recovered, and noise and edge interference is removed too, producing a perfect defect segmentation.  
Figure 4: Result of morphology reconstruction.  
If the high-threshold segmentation image is used to reconstruct the low-threshold segmentation image in the adaptive threshold segmentation algorithm, then the reconstruction result will completely recover the low-threshold segmentation regions tagged by the high-threshold segmentation, completely removing the low-threshold segmentation regions not tagged by the high-threshold segmentation. In other words, morphological reconstruction operation combines the advantages of high-threshold segmentation (low interference) and low-threshold segmentation (complete defects), and thus qualifies as a useful supplement to adaptive threshold segmentation algorithm and minimizes the difficulty of parameter setting for segmentation.