# A UAV-Based Visual Inspection Method for Rail Surface Defects
## 2 Methodology
### The Local Weber-Like Contrast Algorithm for Rail Images Enhancement  
The brightness of images is non-uniform because of uneven natural light, the reflectance properties of rail surfaces [42], vibration of UAVs, or any other environmental factors. Therefore, defects and backgrounds are always mixed together. According to our experience, the following characteristics of UAV rail images occur:  
* Lower variation range of gray values in local regions. The reflection property and illumination of each longitudinal line in rail images is stable [14]. In the local line window, the variation range of gray values has small variation, and the most obvious features can be used for image enhancement [15]. * Greater variation range of gray values in global scope. In general, the rail images have a large variation range of gray level in global scope due to uneven natural light and the reflectance properties of rail surfaces. The reflected light in smooth parts of rail surfaces is more than the rough parts [42]. * Confused gray values between defects and background. In general, the gray value of surface defects is lower than that of background, but the order is often broken because of illumination non-uniformity and noise corruption, as shown in the Figure 4.
* Consistent features in the same longitudinal direction. Actually, a rail surface shares consistent features in the longitudinal direction as a train runs on a rail, since the friction for the points in the longitudinal direction between the rail surface and train wheels has an almost identical impact on the rail surface. In a rail image, intensity for the pixel points along longitudinal direction is consistent with relatively gray value changes caused by defect points and noise points [15]. Therefore, the surface discrete defects can be derived by the analysis of the information in longitudinal regions. * Higher gray mean of each longitudinal line for a track. According to our observation, the gray means along longitudinal lines of a UAV rail image are higher under normal conditions. This is because that UAV are supposed to fly in fine weathers and natural light conditions, and the surface reflectivity of rail tracks in operation is high because of its smoothness, as shown in the Figure 4.  
As Figure 4 shows, the gray means along longitudinal lines of the image is high and the brightness of defects is quite low [14]. Since there are few defects in the image [30], the mean can be considered as background in the longitudinal direction. This feature completely satisfies a suitable range of Weber Contrast. As one of the most classical luminance contrast statistics, Weber Contrast is popular to cope with small, sharp-edged graphic objects on larger uniform backgrounds [43]:  
\[C_{\mathrm{w}}=\,\frac{L_{o}-L_{b}}{L_{b}} \tag{2}\]  
Figure 3: Cumulative gray value of each pixel column for a rail image. Horizontal position denotes location of pixel column. where, \(L_{o}\) is the luminance of the symbol and \(L_{b}\) is the luminance of the immediately adjacent background. When the background is lighter than the object, \(C_{\rm w}\) is negative and ranges from 0 to \(-1\). When the background is darker, \(C_{\rm w}\) is positive and ranges from 0 to potentially very large numbers. Inspired by Weber Contrast and based on these characteristics for UAV rail images, the LWLC algorithm is proposed for adapting to different sunlight illuminance and eliminating the significant changes of gray-scale in this paper. The proposed gray stretch method for defects segmentation will be introduced in the next section. Assuming a pixel \((x,y)\) and its surrounding window \(T\) in a rail image \(l\), the intensity \(LWLC_{(x,y)}\) of each pixel is given by:  
\[LWLC_{(x,y)}\ =\ \frac{I(x,y)-E(I(\widetilde{x},\widetilde{y}))}{E(I( \widetilde{x},\widetilde{y}))},\ (\widetilde{x},\widetilde{y})\in\ T \tag{3}\]  
where, \(I(x,y)\) denotes the gray value of the pixels in the image, \(E\) is the mean of \(I(\widetilde{x},\widetilde{y})\) in \(T\) in window \(T\).