# A Single Image Enhancement Technique Using Dark Channel Prior
## 3 Improved Image Defogging Method Based on Dark Channel Prior
### Improvement of High Time Complexity and Edge Effects of Dark Channel Prior Algorithm
#### 3.1.2 Refinement of Coarse Transmittance Based on Guided Filtering  
After obtaining the rough transmittance by using the dark channel prior, we use guided filtering instead of soft matting to refine the transmittance. Guided filtering has a filtering feature of locally linear smooth-preserving edges, which can be used to repair the rough transmittance obtained by the dark channel prior. The principle is to filter the input image through a guide image, and the output image can fully obtain the detailed changes of the guide image while retaining the overall characteristics of the input image. Compared with soft matting, guided filtering greatly improves the efficiency of the algorithm without affecting the visual effect.  
Guided filtering assumes that there is a local linear relationship between the guided image \(I\) and the output image, that is:  
\[q_{i}=a_{k}I_{i}+b_{k}(i\in w_{k}) \tag{13}\]  
where \(w_{k}\) is a square window, \(k\) is the center pixel, \(a_{k}\) and \(b_{k}\) are linear factors in the window and constant in the window, respectively. Equation (13) represents a linear transformation centered on \(k\) in the image \(I\). This linear transformation ensures that when the guiding image \(I\) in the window has edges, the output image will have corresponding edges. The linear regression method is used to search the window coefficients \(a_{k}\) and \(b_{k}\) with the smallest window cost, and then the local linear filtering with the smallest difference between the input image and the output image is used by the guide image:  
\[E(a_{k},b_{k})=\sum_{i\in w_{k}}((a_{k}I_{i}+b_{k}-p_{i})^{2}+\theta a_{k}^{2})) \tag{14}\]  
where \(\theta\) is an hyper-parameter, and its purpose is to prevent the value of \(a_{k}\) from being too large. The window coefficient can be obtained by linear regression analysis in the literature [14]:  
\[a_{k}=\frac{\frac{1}{|w|}\sum_{i\in w_{k}}(p_{i}I_{i}-u_{k}p_{k}^{\prime})}{ \omega_{k}^{2}+\theta} \tag{15}\]  
\[b_{k}=p_{k}^{\prime}-a_{k}u_{k} \tag{16}\]  
In Equations (15) and (16), \(|w|\) is the number of pixels in the window \(w_{k}\). \(u_{k}\) and \(\omega_{k}\) are the mean and variance of the guide graph in the window \(w_{k}\), and \(p_{k}^{\prime}\) is the mean of the input image in the window \(w_{k}\). As a result that point \(i\) may be contained in different windows \(w_{k}\) and the values of \(a_{k}\) and \(b_{k}\) are different, it is necessary to average the values of \(a_{k}\) and \(b_{k}\) involving all points \(i\). Therefore, the final expression of the guided filtering is obtained:  
\[q_{i}=\frac{1}{|w|}\sum_{k\in w_{k}}(a_{k}I_{i}+b_{k})=a_{i}^{\prime}I_{i}+b_{ i}^{\prime} \tag{17}\]  
Through the above analysis, the specific steps of using the guided filtering to optimize the transmittance are as follows: First, we use the rough transmittance map estimated by the dark channel prior algorithm as the input image \(p\). Then, because the guide image \(I\) needs the edge information to reflect the depth information, we use the gray-scale image of the original image as the guide image \(I\).  
After obtaining the improved atmospheric light value and transmittance, the atmospheric scattering model is used as a physical model for foggy image degradation, and then this model is used to obtain a defogged image. A comparative analysis is performed by using an unimproved dark channel prior algorithm and the improved method proposed in this paper, as shown in Figure 3.  
As we can see from Figure 2(a), after using the dark channel prior to removing the fog, there are obvious edge effects on the tree periphery, the car outline, the signboard periphery, and the road side. At the same time, there is also obvious color cast. However, after using the improved method of this paper to remove the fog, it can be seen from Figure 2(b), the edge effects of trees, cars, signs, and roadsides have been greatly improved, and the color of the image is natural.  
Figure 3: Comparison of the defogging effect of two methods.