# Image-Based Scratch Detection by Fuzzy Clustering and Morphological Features
## 3 Scratch Area Growth Based on Multiple Features  
In binary image _IFB_, some connected regions are isolated and are non-scratched, which need to be further distinguished. In addition, some shallow scratches are not segmented because of the small gray value. In fact, because scratches are usually caused by cutting tools or other sharp objects passing through the surface of mechanical parts, their shapes show obvious strips and maintain strong directional consistency. The direction gradient can be approximated by the mean slope of two pairs of connected domains and the orientation angle of the long axis of each region. The scratch depth varies with the magnitude of the force applied. Therefore, scratches in the image will appear intermittently and have a non-linked morphology. Some isolated areas may be part of the scratch, while discontinuous areas may be missed.  
In order to improve the accuracy of scratch detection, it was necessary to extract the location relationship between regions, the gradient direction of regions, and the local gray distribution around regions [24]. These features will be used to further determine whether the segmentation area is scratched or not.  
First, calculate the minimum distance between regions and constitute distance matrix \(D,D\in R^{\otimes\times s}\), where s is the number of regions in binary image _IFB_, merging the two regions into one if the distance between them is less than distance threshold DT (\(D(i,j)<\text{DT}\), \(i=1,\cdots,s,\ j=1,\cdots,s,\ i\
eq j\)).  
Second, when the scratches on the surface of the piezoelectric ceramic plate are discontinuous and the discontinuous distance is large, it is not enough to merge the regions depending only on the Euclidean distance. According to the linear characteristics of scratches, the discontinuous scratches are approximately distributed on a line as shown in Figure 5a. In Figure 5a, \(k\) represents the slope and \(b\) represents the intercept. The line coefficients \((k_{i},b_{i}),\ i=1,2,\cdots,N\) can be calculated by the least square method on every region. Then, some isolated non-scratched regions are excluded by the critical distance clustering method on the set of regional linear parameters. The clustering results are shown in Figure 5b, where the blue part represents the area reserved and the red part represents the area eliminated.  
If a region is far away from all other regions, it is judged as an isolated region. Isolated regions may be part of the background or scratch, which needs to be further judged by the gray value and membership distribution in the extended area of its outer rectangle. The extended area is a sector-shaped area along the long and short axis of the outer rectangle, with the center point as the circle point, as shown in Figure 5c. In Figure 5c, \(R\) represents the major axis of the circumscribed rectangle, and \(d\) represents the minor axis of the circumscribed rectangle. To further determine whether the isolated area is part of the scratch, the search area is expanded. The enlarged area is parallel to the outer rectangular long axis, and the spacing is twice as long as the outer rectangular short axis. If there are isolated areas in the enlarged area, and the statistical expectations and variances of the combined regions exceed the prescribed range, they will be regarded as scratches [25].  
To further confirm whether the area is part of the scratch, extract the size of each area, fitting line, mean, skewness, kurtosis, etc. In this study, the length and width of the smallest outer rectangle in the region were chosen as the sizes, and the long axis straight line of the smallest outer rectangle was chosen as the fitting line.