2.1. Raw Magnetic Ring Image Acquisition
The image quality obtained by the imaging system is crucial for post-image processing. In order to obtain a clear image of the surface defects of the magnetic rings, we obtained 10 qualified magnetic rings and 150 defective magnetic rings (Shandong Tongfang Luying Electronics Co., Ltd., Shandong, China). The height of the magnetic ring is about 30 mm, the diameter is about 20 mm, and there is a fine crack width of about 0.1 mm on the surface. The magnetic ring is small in size and has a fine and irregular texture, which is difficult to observe with the human eye and general optical imaging devices, especially the radial microcracks submerged in the normal texture. Therefore, a microscope was designed in this study, which is shown in
Figure 2.
The camera used in the experiment had a microscope lens magnification of 10, a focal length of 5 cm, and a resolution of 1 K. The light source is a stable and economical LED lamp (Opple Lighting Co., Ltd., Shanghai, China), the light intensity is 500~700 lux, the illumination mode is diffuse, and a 768 576 dot matrix can be collected. In order to avoid interference from natural light, turn off the room lights before the experiment, turn on the microscope, light source, and computer, and then place the magnetic ring on the rotating stage of the translation stage, which not only realizes millimeter-level translation in the horizontal direction but also realizes the full detail capture of the magnetic ring surface. By adjusting the position of the translation stage appropriately, the camera achieves the best depth of field and field of view.
When acquiring defect images, first, adjust the position of the translation table according to the defect markers so that the camera is roughly aimed at the defect area. Then, the magnetic ring surface defect is looked for by slowly rotating the rotary table. Then fine-tune the distance to the focal length to ensure that the microscope camera captures a clear, complete, and bright image of the defect. Finally, the image information is stored in the computer. If the defect area is large, slowly move the shooting area along the defect texture, starting from the edge point of the defect, so that one edge of the defect coincides with the opposite edge of the previous image. As can be seen in
Figure 3, the image acquisition device is able to clearly detect defects submerged in the texture.
2.2. Image Processing
The accuracy requirement of image segmentation is very important to find the subtle defects. The Gabor filter was customly applied. The Gabor function was first proposed by Dennis Gabor in 1946 [
9]. And in 1985, Daugman pushed the 1D-Gabor filter up to two-dimensions successfully [
10]. The 2D-Gabor filter is a linear filter that can achieve local optimal solutions in both the spatial and frequency domains [
11]. The representation of its frequency and direction is very close to the human visual system [
12], so it is often used for texture description. In addition, Gabor filters have self-similarity, and they can be generated from a mother wavelet through dilation or rotation.
Different parameter values can be obtained from 2D-Gabor filters with different bandwidths, frequencies, and directions. We can use these to filter the target image and extract the image texture feature information with a certain direction and changing law. The 2D-Gabor function can be interpreted as the product of an elliptic Gaussian envelope and a complex plane wave [
13], and is interpreted in the following Formula (1):
where
is the position variable,
is the window size space constant,
is the frequency vector, which represents the scale and orientation of the 2D-Gabor filter.
indicates the center frequency of the Gabor filter.
In Formula (1), the spatial parameter
determines the bandwidth of the filter, and the value is
;
k defines the key parameters
and
for the value of the Gaussian function in this study. It has been shown that the experiment works best when the center frequency does not exceed
in the experiments conducted by M Lades. Therefore, this study takes the maximum sampling frequency
, and the sampling step size
,
. Since the Gabor filter is symmetric, the actual value of
is between [0, π]. Therefore, the value of
is
,
. Thus, a total of 32 real part value images of Gabor filters in 4 scales and 8 directions are formed in
Figure 4.
2.3. Filtering of Scar Defect Images
The process method of using the Gabor filter bank to process the magnetic ring defect image can be interpreted in the Formula (2).
where
represents the input image, and
represents the output image after processing.
is the filter template, and the size of the filter template is selected as (15, 15) in this study. The symbol “
” stands for convolution operation. The original defect image is processed using the above filter bank, and the processed images are shown in
Figure 5. Different scale parameters are represented from top to bottom
, and different direction parameters are represented from left to right
.
In
Figure 5, the larger the filter scale, the stronger the suppression of small noise. In addition, the filtering result changes with the filter direction transformation, and the texture response value to a direction close to the filter direction is larger. The magnetic ring surface images involved in this study all have normal textures generated during production and processing in the horizontal direction. Therefore, the original filter bank is improved, which means that the horizontal direction filter
is screened out to avoid the adverse effect of normal texture on the segmentation of defective areas. The edge direction of the defect area in the magnetic ring image is obvious, and the horizontal texture of the background area has been filtered out. At the same time, other speckle noise appears isotropic with no well-directed edges. Therefore, the isotropic filter response can be suppressed by stacking the filtered images to enhance the difference between the defect and the background area. The superposition process is described in Formula (3).
where
and
represent the same meanings as that in Formula (2), and
represents the superimposing of the output images after processing. Different images, including both initial images and processed images, are indicated in
Figure 6.
In
Figure 7, it can be clearly seen that there are fewer and fewer red areas. This shows that the improved filter set makes the grayscale more uniform, effectively weakens the noise pollution in the image, and makes the difference between defects and background more prominent. Therefore, the improved filter bank processing works better.
In practical terms, in order to simplify the complex convolution operation process, filters with the same window and different scales and directions are usually superimposed first, and then the image is filtered. The process can be expressed in Formula (4):
where
,
, and
represent the same meanings as that in Formula (3).
Here, the image size is assumed to be , and the filter template size is . Thus, the calculation amount is by Formula (3). The calculation amount of the simplified Formula (4) method is: by the simplified Formula (4). Obviously, the calculation was speed by more than one order of magnitude.
The difference between the target defect and the background region is strengthened, which provides preparation for the implementation of adaptive threshold segmentation. The grayscale histogram of the image can clearly reflect the grayscale statistical law after passing through the filter bank.
In order to verify the filtering effect of the improved filter bank on other defective images, we used the improved filter bank to filter the cracks. The filtering effect is also obvious, as shown in
Figure 8.
By the grayscale statistical characteristics, it is indicated that the grayscale histogram of the filtered defect image is dominated by the background pixels that approximately obey the normal distribution. The defect area is represented by a small number of low-gray pixels, and there is an obvious boundary with the pixels in the background area. According to this characteristic, the segmentation threshold can be constructed using Formula (5).
where
and
represent the gray mean and variance of the filtered enhanced image, respectively, and
k is the adjustment factor. The size of
k is related to the gray value characteristic of the enhanced image, and this characteristic can be described by the gray mean value. Through extensive experiments, we define
k as a function of the image mean in a linear Formula (6).
2.4. Adaptive Threshold Segmentation Results
For filter-enhanced image pixels
, the rules for defining adaptive threshold segmentation are illustrated in Formula (5).
Traditional methods of threshold segmentation, such as the common selection iterative method, OTSU method, and maximum entropy method et al., are selected to segment the threshold of a magnetic ring image after Gaussian filter noise reduction, and the results are separately shown in
Figure 9a–c.
On the left of
Figure 10, the processing result is displayed by the threshold segmentation algorithm proposed by this study. Although there is a slight mis-segmentation, it can be eliminated by the area picking method, as shown in the middle of
Figure 10. Finally, after adaptive segmentation and morphological processing based on a 2D-Gabor filter, the magnetic ring scar defect is basically detected. By detecting the minimum circumscribed rectangle of the defect, the defect area of interest can be enveloped, as shown in the right of
Figure 10.
The segmentation thresholds, processing times, and the number of iterations determined by different threshold segmentation algorithms for scar defect images are labeled in
Table 1.
In
Table 1, it can be indicated that our algorithm can accurately separate the defect area from the background area without iterative time. However, the threshold determined by the iterative method and the OTSU method is relatively large. And the segmentation effect of the scar defect on the surface of the magnetic ring is poor. The threshold determined by the maximum entropy method is slightly smaller, as is a certain segmentation effect on dark areas with small defect gray values, especially for large-area defects such as scars. But it cannot be completely segmented.
In order to further verify the superiority of the adaptive threshold segmentation algorithm proposed in this paper compared with other traditional threshold segmentation algorithms, a classifier based on a BP neural network was designed. By comparing the classification results of classifiers under different threshold segmentation methods, the superiority of the proposed algorithm is verified.