## 2 Image Pre-Processing
### Defect Image Acquisition  
We compared and examined the continuously captured PE pipeline images and discovered that \(1\). the percentage of pipeline defects in the entire PE gas pipeline network system is small; \(2\). there is a significant grayscale discrepancy between the defective and normal parts of the grayscale processed defective images; \(3\). after grayscale processing of any two adjacent PE pipeline images, there is a significant grayscale discrepancy between the normal PE pipeline images and the defective PE pipeline images in the same position, while the grayscale discrepancy between the two normal PE pipeline images is very small. Thus, in order to determine whether there are defects in the pipeline images, we propose a screening method for pipeline defects to improve the detection effectiveness [24].  
First, let \(x\) and \(y\) be consecutive images of any adjacent PE pipes in our pipe database, and \(\Delta\) be the greyscale discrepancy between \(x_{k}\) and \(y_{k}\), which is the correspondent pixel locations of the two images \(x\) and \(y\), as shown in Equation (4). However, there will be some information loss during the compression and transmission of the image data [25], which will make the corresponding pixel grayscale values of the two adjacent images differ greatly, even if they are both normal, resulting in incorrect judgments of the system. To decrease this error, we improve the grayscale discrepancy \(\Delta\) of two corresponding pixels to the grayscale discrepancy of the corresponding region \(\overline{\Delta}\), which is the mean of the grayscale discrepancy of all pixels in the designated size region, as shown in Equation (5).  
\[\Delta=|x_{k}-y_{k}| \tag{4}\]  
\[\overline{\Delta}=\frac{1}{S_{n}}\sum_{k=1}^{n}|x_{k}-y_{k}| \tag{5}\]  
Figure 2: Comparison of grayscale processing methods for pipe defect images.  
where \(S_{n}\) denotes number of pixels in designated size region.  
Then, for the minimum mean \(\overline{\Delta}_{1}\) of the pixel grayscale discrepancy between the defective pipeline images and the normal pipeline images computed in the designated size region, a statistical method can be used; the number of pixels with the smallest defect area is calculated statistically as M, let the length of the defect area image be \(M_{l}\) pixels, the width be \(M_{w}\) pixels, as shown in Equation (6).  
\[\text{M}=M_{w}\times M_{l} \tag{6}\]  
Finally, to further improve the accuracy of defect detection, we set the discrepancy \(\overline{\Delta}_{min}\) to be somewhat less than \(\overline{\Delta}_{1}\). When \(\overline{\Delta}\geq\Delta_{min}\), it is judged as abnormal and the number of pixels in the abnormal area is counted as \(B\), when \(\overline{\Delta}<\overline{\Delta}_{min}\), it is judged as normal and the number of pixels in the normal area is counted as \(B1\); calculate \(B1\) and \(B\) according to Equation (6). If \(B\geq M\), then there are defects in \(x\) and \(y\), otherwise \(x\) and \(y\) are considered as normal images.  
More than 9000 consecutive images of pipes were screened using the above defect screening method (Figure 3). A total of 160 out of 163 defective images were picked out, and the screening accuracy rate was up to 98.15%. Figure 3 can better help us understand the PE pipeline defect detection algorithm.