Frontiers in Computing and Intelligent Systems ISSN: 2832-6024 | Vol. 7, No. 2, 2024 6 Research and Analysis of Dark Channel Priori Dehazing Algorithm based on Guided Filtering Haisheng Song *, Nian Liu College of Physics and Electrical Engineering, Northwest Normal University, Lanzhou, Gansu, 730070, China * Corresponding author: Haisheng Song (Email: songhs@nwnu.edu.cn) Abstract: The dark channel priori dehaze algorithm based on minimum filtering is known to consume a significant amount of computational and storage resources for transmittance optimization, resulting in issues such as halo phenomena in gray and white areas of the image. In contrast to this, the proposed algorithm in this paper offers a novel approach to dark channel image dehazing. By leveraging dark channel a priori knowledge, the algorithm introduces an adaptive adjustment factor to enhance the realism of restored image details. Furthermore, the algorithm employs guided filtering for transmittance map refinement instead of traditional image keying. Subsequently, the haze-free image is reconstructed using the estimated atmospheric light and refined transmittance maps based on the atmospheric scattering model. Post image restoration, brightness and contrast are enhanced, and image optimization is achieved through adaptive contrast histogram equalization to improve visual quality. The experimental findings reveal that the proposed algorithm not only accelerates the efficiency of image dehazing but also sustains color fidelity in gray and white regions, yielding aesthetically pleasing outcomes. Keywords: The Dark Channel Priori Dehaze Algorithm; Guided Filtering; Minimum Filtering. 1. Background As society progresses, environmental pollution is on the rise, leading to more frequent instances of haze in cities. This haze poses risks to public health and presents challenges for computer vision systems that heavily rely on image data. Images captured during hazy conditions typically exhibit characteristics such as low contrast, reduced saturation, as well as color distortion and offset issues. Therefore, the primary goal of this research project is to develop a straightforward yet efficient image dehazing technique to enhance the clarity and quality of hazy images. 2. Principle Analysis of the Dark Channel 2.1. Prior Theory This paper implements a dark channel dehazing algorithm based on guided filtering, and the theoretical basis is Dr. Kaiming. He's dark channel dehazing algorithm [1] (CVPR): Single Image Haze Removal Using Dark Channel Prior, his paper counts the features of more than 5,000 images and proves the universality of the dark channel prior theory. 2.2. Dark Channel a Priori Within most images in the local region, some pixels consistently have at least one-color channel with a very low value, leading to a minimum light intensity value that is very small [2]. The dark channel for any input image is defined mathematically by the following equation: min ∈ min ∈ , , (1) In this equation indicates each channel of the color image, and indicates a window centered on pixel .It’s very simple to achieve this expression. Initially, we calculate the minimum value for each channel of the image, followed by applying a minimum filtering process to obtain a grayscale image.[3]. (a) (b) Fig 1. (a) the original images; (b)the images after minimum filtering The window size used in this experiment takes the value of 16, when performing the minimum value filtering, due to the algorithm's own problems, there will be a black edge of the pane size, so it is necessary to expand the image first. The size of the expansion is the size of the window pane, and the expanded value is obtained by copying the outermost value of the pixel matrix, and then the image after the minimax filter is obtained, as shown in Fig .1. The original images waiting to be dehazed, and removed the minimum value of their RGB, the right images are images after minimum filtering [4]. The gray square in the right figure is the pane mentioned previously, the pane generally take the 7 value of 16-30, in which range, the results of image minimum filtering is the best. Every color image will have such a dark channel, and the dark channel a priori algorithm states that: → 0 (2) There are three main reasons for low dark channel values: 1. shadows, such as those inside vehicles, buildings, and windows in cityscape images, or on foliage, trees, and rocks in landscape images; 2. colorful objects or surfaces, such as objects with low reflectivity in any of the color channels (green grass/trees/plants, red or yellow flowers/leaves, and blue water) will result in low values in the dark channel. 3. dark objects or surfaces such as dark tree trunks and rocks. Since outdoor nature images are usually colorful and hazy, the dark channel of these images is dark; 2.3. Hazy Image Imaging Model A model widely used in computer vision and computer graphics to describe haze image formation is shown below: 1 (3) In the equation is the original image, is the image processed without haze, A is the global atmospheric light component, and is the transmittance. Now the known condition is , and it is obvious that cannot be derived directly to get the haze-less image due to the presence of unknowns. There is a need to get some images like the dark channel prior, so the formula is deformed below:c denotes three channels 1 (4) First assuming that the transmittance is constant within each window, defining it as ̃ , and the value of has been given, and then solving the minimization operation twice on both sides to obtain the following equation: min ∈ min ∈ , , ̃ min ∈ min ∈ , , 1 ̃ (5) According to the previous priori theory of dark channels, there is the following equation: min ∈ min ∈ , , 0 (6) then the estimate of the transmittance is: ̃ 1 min ∈ min ∈ , , (7) In real life, there will be some particles in the air, causing us to feel the effect of haze when looking at distant objects[5]. If remove it cleanly, it will make the image look abnormal and lack of realism, it is necessary to save a part of the haze when removing the haze. This design uses a factor of [0, 1] to correct the transmittance , the correction is: ̃ 1 min ∈ min ∈ , , (8) In this experiment, the value of is 0.95, which is theoretically the most consistent with the human visual effect. Fig. 2. shows the original image and the transmittance image, where the left image is the original image and the right image is the valuation image of the transmittance. (a) (b) Fig 2. (a) the original images; (b)the images of the valuation of the transmittance. It can be found that this algorithm estimates the transmittance of the picture is obvious to see a gray square, the original image can be roughly reflected in the edge information. 2.4. The Algorithm of Dark Channel Image Dehazing Algorithm Based on Minimum Filtering In this algorithm, the valuation of the brightest point in the original hazy image as the global atmospheric light component is represented by A, ensuring a minimum valuation of 240 to prevent the original image from being excessively dark. To achieve a good dehazed high contrast map, the transmittance valuation of the image must be normalized. This normalization process allows for the enhancement of image contrast, even in situations where the original image exhibits low contrast characteristics.[6]. When the value of transmittance t is very small, it will result in a large value of J, which will cause the entire preserved image to overshoot towards the white field. Therefore, a threshold can be set in general, so that make when the value of is less than , and all the calculations of the effect image in this paper are based on = 0.1 as the standard. Therefore, the final dehazing formula is: , (9) The effect of the dehazed image obtained according to the above process is shown in Fig. 3. In this study, it was observed that the size of the filter pane directly correlates with the likelihood of containing a dark channel in the images. Furthermore, a darker dark channel is associated with larger filter panes. The parameter has shown to significantly impact the effectiveness of haze removal, with smaller values of resulting in weaker haze removal effects. Subsequently, the focus is now on achieving a more precise transmittance estimation map. To accomplish this, the proposed method in this research involves utilizing 8 guided image filtering to enhance the original map and obtain the transmittance image. Notably, guided image filtering preserves the edges of the transmittance image, thereby enhancing its clarity and ultimately facilitating the generation of high-quality dehazed images.[7][8]. (a) (b) Fig 3. (a) the original images; (b)the images after dehazing. 3. Principle Analysis of the Guided Image 3.1. Filtering 3.2. The Guided Image Filtering Theory For an input image , which has a guided image , the output image is obtained after filtering, where both and are inputs to the algorithm. The guided filtering defines a linear filtering process as shown below, where the filtered output obtained for a pixel point at position is a weighted average: ∑ (10) and denote pixel subscripts, respectively, related only to the guided image . This filter is linear with respect to . An important assumption of guided filtering is that there is a local linear relationship between the output image and the guided image over the filter window : , ∀ ∈ (11) For a deterministic window with radius r, , , is the only deterministic constant coefficient. This ensures that in a local region, if the guided image has an edge, the output image also remains edge invariant because for adjacent pixel points, there exists , and thus as soon as the coefficients , are solved for obtaining the output . The non-edge regions in the input image are also considered that are not smooth as noise , which satisfies .The final goal is to minimize this noise. For each filtering window, the optimization of the algorithm in the least squares sense can be expressed as: ∑ ∈ (12) ∑ ∈ (13) Finally, a regularization parameter ε is employed to make a avoid being too large, and the loss function within the filtering window can be obtained: , ∑ ∈ (14) Solve the optimization process, taking partial derivatives of the function: | | ∑ ∈ ∑ ∈ 15) If | | ∑ ∈ , | | ∑ ∈ ,then the following equation can then be obtained: (16) Organizing the previous formulas yields the following formula: ∑ ∈ 0 (17) after simplifying the expression, ∑ ∈ 0 ∑ ∈ 0 ∑ ∑ ∈∈ ∑ ∈ ∑ ∈ ∑ ∈ ∑ ∈ ∑ ∈ (18) For further simplicity, the p , I are substituted into the above equation after dividing |ω| by both sides. Make I | | ∑ I∈ ,p I | | ∑ p I∈ : (19) The left hand side of the formula are all the mean values in the domain ω associated with the image I , which are obtained according to the formula for the derivation of the variance and expectation: (20) Next just apply the above linear model to the entire filter window of the image. But as can be seen, each pixel point will be contained in multiple windows. For example, if a 3×3 window is used for filtering, then every point except the edge region will be contained in 9 windows. Therefore, for different windows, we will get |ω| values of q . Just average all the values to get the final result: | | ∑ : (21) | | ∑ : , | | ∑ : , This creates a mapping from I to q for each pixel point. 3.3. The Algorithm of Dark Channel Image Dehazing Algorithm based on Guided Filtering In this paper's algorithm, the guided image is the grayscale image to be dehazed. The pane size of the guided filter is four times that of the pane size of the minimum filter. The quoted regularization factor is set at 10 . As a result of the algorithm, the transmittance image of the dehazed image is more refined, as illustrated in Fig. 4. After applying guided filtering to the original image, it becomes apparent that the transmittance image preserves a wealth of edge information while efficiently reducing white edges. This enhancement in image quality surpasses the performance achieved by applying minimum filtering alone. 9 Subsequently, by incorporating this transmittance image into Formula (9), the resulting output can be visualized in Fig. 5. (a) (b) Fig 4. (a)Transmittance image obtained by guided filtering; (b)transmittance image obtained by minimum filtering. (a) (b) Fig 5. (a) the original images; (b)the images after dehazing. 3.4. Analysis and Optimization of Results This paper performs brightness enhancement and contrast enhancement processing of images in addition to implementing a dehazing algorithm for improved dehazing effects. The decision to use these enhancements can be based on the specific requirements of the scene being analyzed. Brightness enhancement involves direct adjustment of the RGB values of the image, while contrast enhancement is accomplished through Adaptive Histogram Equalization (AHE).[9]. By processing the picture in those way, the details of the picture can be enlarged, which provides a convenient way for subsequent picture processing. The graphical effects are analyzed by calculating the peak signal-to-noise ratio , structural similarity [10], and the image mean . Peak Signal to Noise Ratio (PSNR) is the most widely used objective evaluation criterion for images, and its value depends on the error between the original haze map and the corresponding pixels of the recovered image. In other words, PSNRis sensitive to the error, and a larger value indicates less image distortion.PSNR is defined as follows: 10 (22) n is the number of bits per pixel, a typical grayscale image n is taken to be 8 and the gray scale order is 256. MSE is defined as follows: ∑ ∑ , , (23) is the height of the image, w is the width of the image, , are the pixel coordinates, , is the initial hazy image and , is the recovered haze-free image. denotes the mean square error between the original hazy image and the recovered haze-free image, and the smaller the value is, the clearer the recovered haze-free image is. SSIM is based on a perceptual model that evaluates image similarity in terms of 3 dimensions: luminance, contrast, and structure. SSIM is defined as: , , , , , (24) Generally make c c 2. μ is the mean of , is the mean of , is the variance of , is the variance of , and is the covariance of and ,c k L , c k L , is the range of pixel values, and the default valuek 0.01,k 0.03, then there is: , , ∙ , ∙ , (25) Set α, β, γ to 1, then: , (26) is a value in the range of [0,1], the larger the value, the smaller the distortion. The larger the image mean value, the brighter the overall brightness, the clearer the image, and the better the quality of dehazing. The mean value is defined as follows: ∑ ∑ , (27) According to the above formula for the image changes in the calculation of the relevant parameters, the comparison is shown in Fig. 6 and the specific values of each parameter of the test image are obtained as shown in Table 1. Based on the comparison of the data, it is evident that the guided filtering process outperforms the minimum filtering process in terms of various indexes. Specifically, the and values have shown improvement, indicating enhanced image clarity and reduced distortion. This enhancement is visually manifested as a significantly superior dehazing effect in the images processed through guided filtering. Furthermore, the mean value represented by serves as an indicator of image brightness, with the guided 10 filtering process yielding a smaller value compared to the minimum filtering process. Moreover, the image brightness resulting from the bootstrap filtering process is lower than that of the minimum value filtering, resulting in an overall darker image appearance. (a) (b) (c) (d) (e) Fig 6. (a) the original images; (b) images processed by guided filtering; (c) images processed by minimum filtering; (d) images after brightness enhancement; (e) image enhanced by AHE. Table 1. Comparison of parameters after image processing To address this, brightness enhancement and histogram equalization are applied following the guided filtering operation. Subsequent examination reveals that all performance indicators post-enhancement surpasses those attained through the minimum filtering process. Therefore, it is apparent that leveraging guided filtering within the dark channel dehazing framework effectively reduces haze presence in images and significantly enhances their quality. This approach demonstrates promising practical implications. 4. Conclusion Overall, the Guided Filtering based image dehazing algorithm is effective in removing haze from images, except for bright areas such as the sky, where the dark channel a priori algorithm may falter. This can result in inaccurate estimations of atmospheric light and transmittance in these regions, leading to color distortions, offsets, or incomplete dehazing, resulting in an overall dark appearance. To address this limitation, a new model is necessary to recalibrate the transmittance values specifically for bright areas. Despite the potential darkness of the processed image, enhancements such as increasing brightness, contrast adjustments, and histogram equalization can alleviate this issue. Guided Filtering operates on the principle of box filtering, enabling swift processing with a relatively short runtime of approximately four to five seconds on high-speed computational platforms. References [1] He, Kaiming, Jian Sun, and Xiaoou Tang. "Single image haze removal using dark channel prior." IEEE transactions on pattern analysis and machine intelligence 33.12 (2010): 2341- 2353. [2] Chen, Zihong, et al. "Research of polarized image defogging technique based on dark channel priori and guided filtering." Procedia computer science 131 (2018): 289-294. [3] Wu, Miao, et al. "Improvement of dehazing algorithm based on dark channel priori theory." Optik 206 (2020): 164174. [4] Wei, Zhongliang, et al. "An image fusion dehazing algorithm based on dark channel prior and retinex." International Journal of Computational Science and Engineering 23.2 (2020): 115- 123. [5] Pan, Xiaoxi, et al. "Haze removal for a single remote sensing image based on deformed haze imaging model." IEEE Signal Processing Letters 22.10 (2015): 1806-1810. [6] Kim, Se Eun, Tae Hee Park, and Il Kyu Eom. "Fast single image dehazing using saturation based transmission map estimation." IEEE Transactions on Image Processing 29 (2019): 1985-1998. [7] Lu, Zongwei, et al. "Effective guided image filtering for contrast enhancement." IEEE Signal Processing Letters 25.10 (2018): 1585-1589. [8] Li, Shutao, Xudong Kang, and Jianwen Hu. "Image fusion with guided filtering." IEEE Transactions on Image processing 22.7 (2013): 2864-2875. [9] Zimmerman, John B., et al. "An evaluation of the effectiveness of adaptive histogram equalization for contrast enhancement." IEEE Transactions on Medical Imaging 7.4 (1988): 304-312. [10] Setiadi, De Rosal Igantius Moses. "PSNR vs SSIM: imperceptibility quality assessment for image steganography. "Multimedia Tools and Applications 80.6 (2021): 8423-8444.