# Dealing with Low Quality Images in Railway Obstacle Detection System
## 4 Improved Laplacian Edge-Based Blur Detection Method
### Flow Chart of the Proposed Algorithm  
Figure 2(a) depicts the overall flow chart of the proposed algorithm for blur detection. The main idea of the algorithm is the following: first, perform preprocessing of images regarding noise and grayscale formatting, then automatically calculate the night/day thresholds, and finally calculate the variance of the response map. Based on the variance and the values of night/day thresholds, the algorithm can conclude whether the image is blurred or not. In light of the foregoing, the algorithm can be divided into three main steps that are marked in the flow chart with numbers 1, 2, and 3--the preprocessing of images, automatic calculation of blur thresholds, and classification of images, respectively. Real-world railway images obtained from installed cameras must be pre-processed first (see Figure 2(b)). As mentioned above, the Laplace operator uses a second derivative, and, therefore, it is very prone to misinterpretations in the cases where noise is present. Actually, the Laplacian edge detection method localizes edges with the zero crossings of the high-frequency components of images. One difficulty that arises as a result of noise in the high-frequency components is that incorrect zero crossings occur. We can remove the low amplitudes of noise by thresholding the image's high-frequency components since the amplitudes of the high-frequency components of edges are significantly bigger than those of noise [35]. In order to cope with noise, all the produced images from cameras are firstly smoothed out through a two-dimensional Gaussian filter:  
\[G_{\sigma}(x,y)=\frac{1}{\sqrt{2\pi\sigma^{2}}}\cdot\exp\left(-\frac{x^{2}+y^{ 2}}{2\sigma^{2}}\right), \tag{11}\]  
where \(\sigma\) represents the Gaussian distribution standard deviation, and \(x\) (\(y\)) represents the measure between the origin and the horizontal (vertical) axis [49]. After filtering the input image, we convert all the images from a 3D pixel value (RGB) to 1D value, because the colors in the picture do not contribute to the solution of the edge detection problem. As a result, the algorithm is significantly simplified, and the computational requirements are reduced. In the second step (see Figure 4), preprocessed images are used to automatically calculate two threshold values for night and day images. The reason is that in practice, it is noticed that day and night images have different average values for the Laplace variance, imposing the conclusion that working with two separate values leads to better accuracy of the blur image classification. Moreover, manually determining the threshold by trial and error is a time-consuming task with an uncertain outcome, so it is preferable to do it automatically. Automatic threshold calculation means that a part of the pre-processed images is manually classified as blurred or non-blurred, and the images are then divided into four categories: daily blurred, daily non-blurred, nightly blurred, and nightly non-blurred. After that, the mean value of the Laplace variance is calculated for each of these categories. Finally, the daily image threshold is calculated as the arithmetic mean of the average values of the images in the daily blurred and daily non-blurred groups. The same approach is applied for the determination of the threshold for night images. With the calculated thresholds in hand, we can finally classify images as blurred or non-blurred. In this step (see Figure 5), the Laplacian variance is calculated for all preprocessed images in our evaluation database, and images of poor quality are rejected based on the previously determined thresholds. All the images that are not classified as blurry (the variance is greater than the given threshold) are then forwarded to the training database. Figure 3: Proposed algorithm: (**a**) overall flow chart of the proposed algorithm; (**b**) pre-processing.