# A Nighttime and Daytime Single-Image Dehazing Method
## 3 Proposed Dehazing Method
### Mixed-Filter for Ambient Illumination Estimation  
According to Retinex theory, we can Substitute (1) into (4):  
\[I(x)=A(x)(R(x)t(x)+1-t(x)) \tag{5}\]  
Ambient illumination, composed of the scattering and reflection of atmospheric light and artificial light sources is a spatially smooth and low-frequency term while \(R(x)t(x)+1-t(x)\) serves as the high-frequency term. The traditional Retinex algorithm uses Gaussian filtering to estimate the low-frequency components. However, because Gaussian filtering does not retain the edge and it is isotropic, the shape of the light source and the direction of the light cannot be retained when the image is blurred, and the backlight area of the light source is also blurred. Considering this analysis, we propose to initially preserve the edge blur of the brightness of the hazy image. While retaining the shape of the light source and the direction of the light, filter the farther small light source and reflected light, and then pass it as the reference image to guide the filtering as the ambient illumination estimation. We regard each target pixel as a potential edge and generate multiple local windows (called side windows) in the rectangular area around it. Each window aligns the target pixel with the edge or corner (rather than the center) of the window. In the discrete cases, define eight side windows: upper (U), lower (D), left (L), right (R, upper left (UL), upper right (UR), lower left (DL), and lower right (DR). The eight side windows are mean filtered with  
Figure 1: Flow chart of the proposed dehazing method. In this chart, the red line is the ambient illumination estimation method, the blue line is the transmission estimation method, and the green line is the result. the original image, and the side window with the minimum Euclidean distance between the filtering result and the original image is selected as the optimal filtering side window of the target pixel. The process can be expressed as follows:  
\[L_{n}=\frac{1}{N_{n}}\sum_{j\in\omega_{i}^{n}}\omega_{ij}I_{j},N_{n}=\sum_{j\in \omega_{i}^{n}}\omega_{ij}\,n\in S \tag{6}\]  
where \(L_{n}\) is the filter value of the sub-window, \(\omega_{ij}\) is the weight of the pixel \(j\) near the target pixel \(i\) based on the kernel function \(F\) which is averaging; \(I_{j}\) is the value of pixel \(j\), and \(S=U,D,L,R,UL,UR,DL,DR\) is the set of sub-window index. After obtaining the filter values of the eight sub-windows, in order to preserve the edge information, we use the sub-window with the minimum Euclidean distance to the input intensity as the output of \(L_{sw}\). \[L_{sw}=arg\underset{n\in S}{\min}\ \parallel I_{i}-L_{n}\parallel_{2}^{2} \tag{7}\]  
We assume that the guided image and the output ambient illumination are linear, and then the brightness filtered image \(L_{sw}\) is used as the guide image to obtain the linear transform parameter by minimizing the cost function of the target image \(I\) :  
\[\mathrm{E}(a_{k},b_{k})=\sum_{x\in\omega_{k}}\left(\left(a_{k}L_{sw}(x)+b_{k}- I(x)\right)^{2}+\lambda a_{k}^{2}\right) \tag{8}\]  
where \(\omega_{k}\) is the filter window, \(\lambda\) is the regularization coefficient with a value of 0.01, which is mainly used to prevent the solution \(a_{k}\) from being too large. Solve (8) using the least square method as follows:  
\[\left\{ \begin{array}{c}a_{k}=\frac{\frac{1}{|\omega|}\sum_{i\in\omega_{k}}L_ {sw}l_{i}-\mu_{k}l_{k}}{\sigma_{k}^{2}+\lambda}\\ b_{k}=I_{k}-a_{k}\mu_{k}\end{array} \right. \tag{9}\]  
where \(\mu_{k}\) and \(\sigma_{k}^{2}\) are the mean and variance of \(L_{sw}\) in window \(\omega_{k}\), \(|\omega|\) is the number of pixels in the window; \(l_{k}\) is the mean value of all elements in the filter \(\omega_{k}\).