# Defect Detection in Striped Images Using a One-Dimensional Median Filter
## 2 Materials and Methods
### Flow of Defect Detection
#### 2.3.2 Image Segmentation  
The image segmentation process is shown in Figure 5. The purpose of this step is to segment the image into blocks and intervals, because different approaches are used for defect detection in blocks and intervals in the paper. The image shown in Figure 6a is used to explain the step. First, all connected blocks are identified, as shown by the red boundaries in Figure 7a, and the bounding box that can contain an entire connected block must be calculated for each block. All the connected blocks were marked from one to nine, as shown in Figure 7. The bounding boxes, shown as green boxes in  
Figure 4: Flow of pre-processing.  
Figure 3: Flow of the overall defect detection algorithm for striped images.  
Figure 7b, can be used as masks to separate the blocks and intervals. The masks for the blocks based on the bounding boxes, shown in Figure 7b, are illustrated in Figure 7c. Due to the influence of the defect circled in Figure 7b, the bounding box in the middle is incorrect. To remove the effect of the defect on the bounding boxes, we can take the following approach: For the three connected blocks, blocks 2, 5, 8, the \(x\)-coordinate value of the leftmost pixel in each row of these blocks can be obtained, and the median of all the values obtained can be used as the \(x\)-coordinate of the bounding box on the left-hand side of connected blocks 2, 5, and 8. By using the same way, we can find all the other sides of the bounding boxes for all the connected blocks. Because the number of pixels of all the defects in an entire image is less than 1% of the total pixels for all the images we have, this approach can correctly find all the bounding boxes.  
As explained previously, the spacing between the blocks in each image is the same. After measuring the pixel distance of the image spacing, we found that \(x_{d1}=x_{d2}=85\) pixels and \(y_{d1}=y_{d2}=135\) pixels, as shown in Figure 6b. From the correct bounding boxes and the fixed block spacing, the blocks and intervals can be correctly segmented.  
Figure 5: Flow of image segmentation.  
Figure 6: (**a**) The original image with defects in the middle block and the intervals; (**b**) the block numbers and the widths of the intervals are illustrated.  
Figure 7: (**a**) The red lines and curves are the boundaries of the connected blocks, and a defect is marked with a blue circle; (**b**) the green boxes are the bounding boxes of the connected blocks; (**c**) The mask obtained by the bounding boxes in (**b**) is affected by the defect circled in (**a**,**b**).  
Figure 8a shows the mask for the blocks. When the mask is applied to the image shown in Figure 6a, the image of the blocks can be segmented, as shown in Figure 8b. The red circle indicates a defect in the block.  
The mask for the intervals, shown in Figure 9a, can be obtained by complementing Figure 8a. When Figure 9a is applied to the original image, as shown in Figure 6a, the image of the intervals can be segmented, as shown in Figure 9b. The red circle indicates a defect in the interval.