# High-Brightness Image Enhancement Algorithm
## 3 Proposed Method
### Optimization and Implementation  
It is difficult to minimize Formula (3) directly because it contains several unknowns. For each group of linear coefficients \(m_{i}\) and \(n_{i}\), the definitions exist only in a single window, so the minimization problem of Formula (3) can be expressed as:  
\[ \begin{split}\arg\min_{m,~{}n,~{}l^{l}}f=\arg\min_{l^{l}}\sum_{i} \arg\min_{m_{i},~{}n_{i}}f_{i}~{},\\ \text{where}~{}f_{i}=\left\{\sum_{j\in wi}\left[l^{l}(j)-m_{i}l^{h} (j)-n_{i}\right]^{2}+\mu c_{i}^{-2}(m_{i}-c_{i})^{2}\right\}\end{split}  \tag{4}\]  
Through this expression, by computing the partial derivatives of function \(f_{i}\) for \(m_{i}\) and \(n_{i}\) setting them to zero, we obtain the optimal summed solution and obtain the optimal \(\hat{l}^{l}\) after solving the linear equation. The calculation process is as follows:  
\[\left.\frac{\partial f_{i}}{\partial p_{i}}\right|_{m_{i}=m_{i}^{*},~{}n_{i}= n_{i}^{*}}=2\varepsilon c_{i}^{-2}(m_{i}^{*}-c_{i})-\sum_{j\in w_{j}}2\left[l^{l} (j)-m_{i}^{*}l^{h}(j)-n_{i}^{*}\right]l^{h}(j)=0 \tag{5}\]  
\[\left.\frac{\partial f_{i}}{\partial q_{i}}\right|_{m_{i}=m_{i}^{*},~{}n_{i}= n_{i}^{*}}=-\sum_{j\in w_{j}}2\left[l^{l}(j)-m_{i}^{*}l^{h}(j)-n_{i}^{*} \right]=0 \tag{6}\]  
Formulas (5) and (6) can be expressed as a linear relationship:  
\[K_{i}\cdot[m_{i}^{*}n_{i}^{*}]^{T}=W_{i} \tag{7}\]  
where  
\[K_{i}=\left[ \begin{array}{cc}\varepsilon c_{i}^{-2}+\sum\limits_{j\in w_{j }}l^{h}(j)^{2}&\sum\limits_{j\in w_{j}}l^{h}(j)\\ \sum\limits_{j\in w_{j}}l^{h}(j)&\sum\limits_{j\in w_{j}}1\\ \end{array} \right]\]  
\[W_{i}=\left[ \begin{array}{cc}\varepsilon c_{i}^{-2}+\sum\limits_{j\in w_{i }}l^{h}(j)\cdot l^{l}(j)\\ \sum\limits_{j\in w_{j}}l^{l}(j)\end{array} \right]\]  
By solving Formula (7), we can obtain:  
\[[m_{i}^{*}n_{i}^{*}]^{T}=K_{i}^{-1}\cdot W_{i}=\frac{1}{m_{i}\cdot\Delta_{i}} \left[ \begin{array}{cc}1&-\mu_{i}\\ -\mu_{i}&\Delta_{i}+\mu_{i}^{2}\end{array} \right]\cdot W_{i} \tag{8}\]  
where  
\[m_{i}=\sum\limits_{j\in w_{i}}1\]  
\[\mu_{i}=\frac{1}{x_{i}}\sum\limits_{j\in w_{j}}l^{h}(j)\]  
\[\Delta_{i}=\sigma_{i}^{2}+\left(\frac{\varepsilon c_{i}^{-2}}{m_{i}}\right)\]  
By taking the partial derivatives of the function \(f\) to \(l^{l}(k)\) and setting them to zero, we have:  
\[\left.\frac{\partial f}{\partial l^{l}(k)}\right|_{l^{\prime}=l^{\prime}}= \sum_{i|k\in w_{i}}2\left[\hat{l}^{l}(k)-m_{i}^{*}\hat{l}^{h}(k)-n_{i}^{*} \right]=0 \tag{9}\]Combining (8) and (9), we can obtain:  
\[ \begin{array}{l}\frac{\partial f}{\partial l^{\prime}(k)}\Big{|}_{l^{\prime}=F}= \\ \sum_{i|k\in\mathfrak{w}_{i}}\left(\hat{l}^{I}(k)\frac{1}{m_{i}\Delta_{i}}\left( \begin{array}{c}\epsilon c_{i}{}^{-1}l^{h}(k)+l^{h}(k)\sum_{j\in\mathfrak{w}_{ i}}l^{h}(j)l^{\dagger}(j)-\mu_{i}l^{h}(k)\sum_{j\in\mathfrak{w}_{i}}l^{ \dagger}(j)\\ -\mu_{i}\epsilon c_{i}{}^{-1}-\mu_{i}\sum_{j\in\mathfrak{w}_{i}}l^{h}(j)l^{ \dagger}(j)+\left(\Delta_{i}+\mu^{2}\right)\sum_{j\in\mathfrak{w}_{i}}l^{ \dagger}(j)\end{array}\right)\right)=0\end{array}  \tag{10}\]  
Because of the linearity of Formula (10), it can be simplified as follows:  
\[D\cdot\hat{l}^{I}=B \tag{11}\]  
where  
\[d_{kj}=\frac{\partial^{2}f}{\partial l^{\prime}(k)\partial\hat{l}^{\prime}(j) }=\sum_{i|\{k_{j}\}\subset\mathfrak{w}_{i}}\left(\delta_{kj}-\frac{1}{m_{i} \Delta_{i}}\Big{[}\Big{(}I^{h}(k)-\mu_{i}\Big{)}\Big{(}I^{h}(j)-\mu_{i}\Big{)} +\Delta_{i}\Big{]}\right)\]  
\[b_{k}=\sum_{i|k\in\mathfrak{w}_{i}}\frac{\epsilon}{m_{i}\Delta_{i}c_{i}}\Big{[} I^{h}(k)-\mu_{i}\Big{]}\]  
\(\delta_{kj}\) is a Kronecker delta. The optimal solution of Formula (3) is obtained by solving Formula (11). The matrix \(D\) in (11) is symmetric and sparse. In each row \(i\) of \(D\), the number of nonzero elements reaches the area defined according to (11). Given an input image including \(N\) pixels, where the size of the window \(w_{i}\) is set to \(k\times k\), \(D\) has fewer than \(N\times(2k-1)^{2}\) nonzero elements (a \(k=5\) example is shown in Figure 2).