## 3 Real-Time Small Pit Defect Detection Network
### Extracting Candidate Image Patches for Pit Detection
#### 3.2.2 Cropping of Positive Region
Figure 6e shows the results of a difference operation conducted on a grayscale image with the resulting image of the opening operation in Figure 6b. Consequentially, the edge areas are emphasized. A weighted sum of the feature maps of which the inner and edge regions of the pits have become more visible is performed to make the weak-level pits more distinct. During this process, although the background noise may also become clear, it can prevent non-detection of weak-level pits. Figure 6f,g show the results of clearly enhancing the pit regions by applying a weighted sum of the feature maps obtained through the aforementioned difference operation and one more weighted sum on the closing operation results with the brightest pit regions. A comparison of the resulting image in Figure 6g with the image in Figure 6c shows that the contrast between the pit regions and background is clearer. When a difference operation applies the image in Figure 6g, which has enhanced pit regions and the image in Figure 6b, an image having clearly distinguished pit regions is obtained, as shown in Figure 6h. By improving the contrast in this way, it becomes easier to find the threshold value when conducting adaptive binarization to extract candidate regions, and the quality of the binarization is therefore improved. In order to prevent the intermittent loss of information, Figure 6i is obtained by the difference operations between Figure 6h,d where the internal regions are clearly emphasized. Finally, Figure 6k can be obtained using Otsu binarization, which is an adaptive method, and then inverting the result. The Otsu algorithm sets the threshold k so that it maximizes the variance \(\sigma_{B}^{2}(k)\) among classes in a histogram of the image [13]. \[\sigma_{B}^{2}(k)=\frac{\left[m_{G}P_{1}(k)-m(k)\right]^{2}}{P_{1}(k)[1-P_{1}(k)]} \tag{6}\]  
In Equation (6), \(m_{G}\) is the average brightness of the entire image and \(P_{1}(k)\) is the probability of the occurrence of a set consisting of the components of a histogram from brightness label 0 to k. Furthermore, \(m(k)\) is the average brightness of the accumulated value up to label k. Pit defects and the background regions can be clearly distinguished by calculating the parameters \(m(k)\) and \(P_{1}(k)\), according to the k value, and finding a threshold value for dividing the image that maximizes the variance among classes. During the multiple feature map synthesis process, the noise of the background regions may also become distinct, which may increase in the number of candidate region image patches. To resolve this problem, morphology operations that are mainly used for noise removal are applied in sequence to obtain a resulting image with the fine noise of the background regions removed, as shown in Figure 6l. The final resulting image is divided into regional units through four-connectivity labeling. Finally, based on the observation that the maximum size of the pit defects is approximately 10 \(\times\) 10 pixels owing to the characteristics of the defects, all regions larger than the maximum size of pits are removed. However, if the condition of the image is poor, a much higher amount of noises will be included in comparison to the number of pit defects. This problem occurs when the background noise with a faint edge or dot-like shapes is also enhanced during the multiple feature map synthesis process. Although most of the candidate regions' image patches can be adequately classified during the classification process, the following contrast-based filtering was applied to reduce the overhead of the classification process. Figure 7 shows the contrast-ratio-based filtering process for the \(i^{th}\) image patch out of N total candidate regions. Among the methods used to find the contrast ratio of an image, a histogram-based method is more sophisticated. However, considering the overhead, we  
Figure 6: Morphology operation results executed to extract and synthesize multiple feature maps; (a)–(l).