# Dealing with Low Quality Images in Railway Obstacle Detection System
## 2 Blur in Images  
To successfully design an adequate algorithm for blur detection, it is critical to comprehend the underlying concept behind the blurring distortion. Blurring is one of the most common types of image distortion in photographs and represents a shape or an area in an image that cannot be clearly seen because it does not have a clear outline or because it moves very fast, in the case of video material. Practically, blurring is the attenuation of high frequencies, which affects the frequency spectrum of the image. Depending on the conditions under which the image blur occurs, we can distinguish between two types: motion blur and out-of-focus blur. The first type of blurness, motion blur, presented in Figure 1b, occurs as a result of either the movement of an object in the camera's field of vision during shooting, or the movement of the camera itself. Within this type of blur, we can also distinguish between global and local blur (spatially varying blur). Global blur occurs when the scene is static, and blurring occurs as a result of camera movement during the exposure process, while local blur occurs as a result of the movement of individual objects while other components are static. In the second type (out-of-focus blur), blurring occurs as a result of insufficient camera focus during exposure to objects of interest (Figure 1c). Insufficient focus may be due to inadequate handling of the equipment or its design, e.g., poor quality lenses and sensors. Of course, there is also the possibility of the simultaneous combination of conditions that lead to blend blur. All the above situations are common in railway case studies. In [12], it is shown that the blurring process can be defined as  
\[B=A\otimes k+n, \tag{1}\]  
where \(B\) represents the blurred image, \(A\) is the clear image, \(\otimes\) denotes the convolution operator, \(k\) is the blur kernel, and \(n\) corresponds to the noise. Blur kernels are strictly correlated with the blur type, so, for instance, a mathematical model of motion blur in the form of a line can be represented by the following kernel:  
\[k_{\text{motion}}(x,y)=\left\{ \begin{array}{ll}\frac{1}{L},&\text{if }\sqrt{x^{2}+y^{2}}\leq L,\ \ \tan\theta=\frac{y}{x}\\ 0,&\text{else,}\end{array} \right. \tag{2}\]  
Figure 1: Illustration of different blur types: (**a**) non-blur; (**b**) motion blur; (**c**) out-of-focus blur. where \(x\) and \(y\) denote the horizontal and vertical coordinates, respectively. \(L\) represents the blur scale, and \(\theta\) is the blur angle. It should be noticed that the sum of all the elements of \(k\) is 1. In a similar way, by implementing kernel  
\[k_{\text{defocus}}(x,y)=\left\{ \begin{array}{ll}\frac{1}{\pi R^{2}},&\text{if } \ x^{2}+y^{2}\leq R^{2},\\ 0,&\text{else},\end{array} \right. \tag{3}\]  
we can describe the mathematical model of out-of-focus blur in the form of a disk, where \(R\) is the blur scale. It is obvious that the mathematical model of a blend blur kernel can be obtained by convolution of previous blur kernels (2) and (3) in the form of  
\[k_{\text{blend}}=k_{\text{motion}}\otimes k_{\text{defocus}}. \tag{4}\]  
The automatic detection and classification of blurred images or their parts can be considered as part of the blur elimination (de-blurring) process in the form of image quality assessment for further improvement processes. If there is a mathematical description of how the image was blurred, then the de-blurring method becomes easier. When there is no mathematical explanation of how the image became blurred, different methods can be used to estimate the blur. Figure 2 shows an example of the created graphical user interface developed in AppDesigner from MATLAB for the de-blurring process using a pseudo-inverse filter for image restoration. Test images can be loaded, and image processing techniques for de-blurring can be applied.