# Defect Detection in Striped Images Using a One-Dimensional Median Filter
## 2 Materials and Methods
### Flow of Defect Detection
#### 2.3.3 Defect Detection in Blocks  
After the image is segmented, defect detection for blocks can be conducted. The flow is shown in Figure 10. The median filtering is applied to the block images first to generate the standard defect-free images. The median filtering cannot remove large stains, so the large stains must be processed using a different approach. Then the proposed method subtracts the defect-free image from the original image to find the defects in the blocks. The details of the step are described below.  
Figure 8: (**a**) The mask for the blocks. (**b**) The image of the blocks segmented using the mask in (**a**) and a defect is marked with a red circle.  
Figure 9: (**a**) The mask for the intervals. (**b**) The image of the intervals segmented using the mask in (**a**) and the defect is marked with a red circle.  
As shown in Figure 11, each block image is divided into several sections with a width of \(m\) pixels. How to determine the value of \(m\) is discussed in the next section. Applying the one-dimensional median filtering row by row in each section of a block image, a defect-free block image is obtained if there are no large stains. Here, Section 1 in Figure 11 is used as an example. Figure 12a shows the image before and after the one-dimensional median filtering is applied. It can be seen that the defects are removed.  
For large stains, if the number of pixels with stains in a row is greater than half of the section width \(m\), then the grayscale values of the whole row will be replaced by the grayscale value of the stain, and the one-dimensional median filtering fails. The situation is illustrated in Figure 12b. Therefore, another approach is required for large stains. According to statistics of the images provided, the lowest grayscale value for the background pixels was about 80, and the grayscale value for the large stains was about 40. Therefore, if the grayscale difference was greater than 40, it meant that there was a large  
Figure 11: Block image divided into sections with width \(m\) pixels.  
Figure 10: Flow of defect detection in blocks.  
tain. After the locations of the large stains are found, the appropriate threshold for image binarization can be used on the original images to obtain the locations of the large stains.  
Other defects, such as small stains and scratches, are detected by applying image subtraction to the original defect images and the defective-free images. The defect-free images, which are processed by the one-dimensional median filter, should have grayscale values similar to those of the original images, with the exception at defect locations. Therefore, after image subtraction, image binarization can be used to locate the defects. Here, Block 5, shown in Figure 13, is used as an example. Figure 13a shows the original defect image, and Figure 13b shows the image after the one-dimensional median filter has been applied to remove the defects. Subtracting Figure 13b from Figure 13a and using image binarization on the result yields the image shown in Figure 14a, in which the white defects (red circled) are identified. Conversely, subtracting Figure 13a from Figure 13b and using image binarization on the result yields the image shown in Figure 14b, in which the black defects (red circled) are identified. How to determine the binarization threshold, \(T_{r}\), will be discussed in the next section. All defects in blocks can thus be found using the procedure described above for all blocks.