# Low-Light Mine Image Enhancement Algorithm Based on Improved Retinex
## 3 Proposed Method
### Improved Guided Filtering  
Guided image filtering (GIF) was first introduced by [PERSON] et al. [13], and its process can be regarded as an ordinary linear translation transform filtering model. The satisfied linear relationship is  
\[q_{i}=a_{k}I_{i}+b_{k},\forall i\in w_{k}, \tag{4}\]  
where \(q_{i}\) is the linear conversion of the guide image \(I_{i}\) in the local window; the linear coefficients of the corresponding window are represented by \(a_{k}\) and \(b_{k}\); and \(w_{k}\) is a local window with a radius, \(r\), and a center pixel, \(k\). The linear coefficients are fitted using the least squares method [14], and the cost function is  
\[E(a_{k},b_{k})=\sum_{i\in w_{k}}\left((a_{k}I_{i}+b_{k}-p_{i})^{2}+\varepsilon a _{k}^{2}\right), \tag{5}\]  
where \(\varepsilon\) refers to a fixed regularization term used to avoid the value \(a_{k}\) from becoming overly large [15]. Weighted guided image filtering (WGIF) introduced an edge weighting factor \(\Gamma_{I}(k)\)[16] based on GIF to adaptively adjust the regularization parameter. \(\Gamma_{I}(k)\)is defined as follows:  
\[\Gamma_{I}(k)=\frac{1}{N}\sum_{i=1}^{N}\frac{\sigma_{I,1}^{2}(k)+\psi}{\sigma _{I,1}^{2}(i)+\psi}, \tag{6}\]  
where \(N\) refers to the overall pixel count; \(\sigma_{I,1}^{2}(k)\)is the variance of the guide image that denotes the varying scope of values in the input image of \(3\times 3\) window [17]; \(\psi\) is a very small constant, which in general takes the value of \((0.001\times L)^{2}\); and \(L\) reflects the range of values presented in the input image. Although WGIF reduces the halo blurring phenomenon at the boundary, its edge-aware factor is determined by assessing the variance within local windows at different areas. However, the areas with larger variance are not always edge areas and are insensitive to the weak edge areas in the image. Therefore, the gradient information is introduced into the new edge-aware weight; at the same time, it can enhance the capability to perceive subtle edges in the image, thus improving the robustness of the algorithm. The proposed new edge-aware weight is calculated by  
\[\hat{\Gamma}_{I}(k)=\frac{1}{N}\sum_{i=1}^{N}\frac{\varphi(k)+\psi}{\varphi(i) +\psi}, \tag{7}\]  
new edge protection constraint \(\gamma(k)\) is proposed to preserve the edge while retaining the slight details in the comparatively smooth regions. The expression of \(\gamma(k)\) is  
\[\gamma(k)=\frac{1}{1+e^{-g(k)}}, \tag{8}\]  
where \(g(k)\) is the gradient size of the pixel \(k\). When it is located in the edge area, the magnitude of \(g(k)\) is larger and \(\gamma(k)\) is closer to 1; when it is located in the smooth area, the magnitude of \(g(k)\) is smaller and \(\gamma(k)\) is closer to 0. Therefore, the new cost function is changed to  
\[E(a_{k},b_{k})=\sum_{i\in w_{k}}\big{[}(a_{k}I_{i}+b_{k}-p_{i})^{2}+\frac{ \varepsilon}{\bar{\Gamma}_{I}(k)}(a_{k}-\gamma_{k})^{2}\big{]}. \tag{9}\]  
Thus, the best values for \(a_{k}\) and \(b_{k}\) are determined as  
\[a_{k}=\frac{\frac{1}{|u|}\sum_{i\in w_{k}}I_{k}p_{k}-\mu_{k}\overline{p}_{k}+ \frac{\varepsilon}{\bar{\Gamma}_{I}(k)}\gamma(k)}{\sigma_{k}^{2}+\frac{ \varepsilon}{\bar{\Gamma}_{I}(k)}}, \tag{10}\]  
\[b_{k}=\overline{p}_{k}-a_{k}\mu_{k}, \tag{11}\]  
where \(\mu_{k}\) and \(\overline{p}_{k}\) are the mean values of the guide image and the input image in the window \(w_{k}\), respectively; \(\sigma_{k}^{2}\) is the variance of the guide image in the window \(w_{k}\); and \(|w|\) is the amount of pixel \(k\). Putting the magnitude of \(a_{k}\) and \(b_{k}\) into Equation (4), the expression for the output image can be represented as  
\[q(i)=\overline{a}_{i}I(i)+\overline{b}_{i}, \tag{12}\]  
where \(\overline{a}_{i}\) and \(\overline{b}_{i}\) are the average values of \(a_{k}\) and \(b_{k}\) within the window \(w_{k}\), respectively.