## 3 Real-Time Small Pit Defect Detection Network
### Extracting Candidate Image Patches for Pit Detection
#### 3.2.2 Cropping of Positive Region  
The goal of the pit candidate region extraction stage is to minimize the background region noise in the positive region and to detect the pit defects. As the number of candidate area image patches input into the CNN increases, the detection speed decreases; therefore, the number of candidate areas should be minimized, including all possible pit defects. To minimize the processing time during the candidate region extraction stage, this approach adopts morphology operations that have been used in real-time small object detection studies [25; 26]. Morphology operations can be used to suppress noise and enhance the features of object regions to detect small objects that appear as tiny dots in infrared images captured at a distance. Furthermore, these can be used to extract  
Figure 5: Positive region extraction process; (**a**) input image, (**b**) binarization result, (**c**) extracted positive region. desired data using the information of a target object with a known geometric shape. The applied method is a simple approach in which a structure element, which is a kernel suitable for the shape and size of the target, is moved to all regions of the image and the operations are conducted. The advantage of morphology operations is that the computation overhead is extremely small; therefore, it is suitable for real-time pit defect detection that is targeted in this paper. Equations (2)-(5) show the dilation, erosion, opening, and closing operations, respectively. \[[\mathrm{I}\oplus\mathrm{b}](\mathrm{x},\;\mathrm{y})=\max[\mathrm{I}( \mathrm{x}-\mathrm{p},\;\mathrm{y}-\mathrm{q})+\mathrm{b}(\mathrm{p},\;\mathrm{ q})] \tag{2}\]  
\[[\mathrm{I}\ominus\mathrm{b}](\mathrm{x},\;\mathrm{y})=\max[\mathrm{I}( \mathrm{x}+\mathrm{p},\;\mathrm{y}+\mathrm{q})-\mathrm{b}(\mathrm{p},\;\mathrm{ q})] \tag{3}\]  
\[[\mathrm{I}\circ\mathrm{b}](\mathrm{x},\;\mathrm{y})=(\mathrm{I}\ominus \mathrm{b})\oplus\mathrm{b} \tag{4}\]  
\[[\mathrm{I}\cdot\mathrm{b}](\mathrm{x},\;\mathrm{y})=(\mathrm{I}\oplus\mathrm{ b})\ominus\mathrm{b} \tag{5}\]  
Here, I is the original image, x, y are the original image coordinates, and p, q are the coordinates of the structure element. In addition, because pit defects have a round shape, an ellipse structure element was used. Figure 6 shows the results of multiple feature map extraction for morphology operation-based pit defect candidate region detection. Figure 6b shows the results of the opening morphology operation for the grayscale image in Figure 6a. The opening operation has the effect of removing small-sized light pixels during the dilation process after an erosion operation. By contrast, Figure 6c shows the results of the closing operation, which has the effect of removing dark regions through erosion after a dilation operation. Here, in the case of strong-level pits, the pit regions are shown clearly using only the closing operation, whereas the weak-level pits are not shown clearly at this stage. In addition, because of the light pixels in the background regions in the results of the closing operation, a significant amount of noises may be included in the binarization results, or it may be difficult to find the binarization threshold value. To resolve this problem, this study adopted an approach to extract multiple feature maps that suppress the background region noise and more clearly enhance weak-level pits. Multiple feature maps are extracted through addition and difference operations conducted on each feature map based on the morphology operation results. First, Figure 6d is an image obtained through a difference operation applied to the results of the opening and closing operations. The difference operation is used to block the background noises in the image and obtain a localized bright region. As can be seen in the resulting image, the background region is darkened while the pit defect region is brightened, making it clearly visible.