# Dual Histogram Equalization Algorithm Based on Adaptive Image Correction
## 3 Proposed AICHE Transformation
### Adaptive Local Grayscale Correction
#### 3.2.2 Local Gray Level Correction  
To solve the problem that the gray levels will be merged after equalization, the AICHE algorithm corrects the image after equalization. First, the gradient value is obtained by convolving the input image and the equalized image with the Sobel operator to find the location where the gradient value is obviously reduced. Second, the gray value is modified with reference to the original image to enhance the local gradient value to protect the image detail information. The specific process is as follows.  
1. The gradient matrices \(D_{in}\) and \(D_{HE}\) of the input image and the equalized image are obtained by convolving the images \(F\) and \(P_{T}\) with Sobel operators in four directions. The gradient matrix convolution is calculated as follows: \[\begin{aligned} D_{in}&=\sqrt{(D_{0^{ \circ}}*F)^{2}+(D_{180^{\circ}}*F)^{2}+(D_{45^{\circ}}*F)^{2}+(D_{135^{\circ}}* F)^{2}}\\ D_{HE}&=\sqrt{(D_{0^{\circ}}*P_{T})^{2}+(D_{180^{ \circ}}*P_{T})^{2}+(D_{45^{\circ}}*P_{T})^{2}+(D_{135^{\circ}}*P_{T})^{2}}\\ \end{aligned}\] (17) where \(D_{0^{\circ}}\), \(D_{45^{\circ}}\), \(D_{135^{\circ}}\), \(D_{180^{\circ}}\) denote the convolution factors in the four directions of \(0^{\circ}\), \(45^{\circ}\), \(135^{\circ}\), and \(180^{\circ}\), respectively. The four convolution factors are \[\begin{aligned} D_{0^{\circ}}&=\left[\begin{array}{ cccc}-1&0&1\\ -2&0&2\\ -1&0&1\\ \end{array}\right];& D_{180^{\circ}}=\left[\begin{array}{ccc}-1&-2&-1\\ 0&0&0\\ 1&2&1\\ \end{array}\right];& D_{45^{\circ}}&=\left[\begin{array}{ccc}2&1&0\\ 1&0&-1\\ 0&-1&-2\\ \end{array}\right];& D_{135^{\circ}}&=\left[\begin{array}{ccc}0&-1&-2\\ 1&0&-1\\ 2&1&0\\ \end{array}\right];& D_{135^{\circ}}&=\left[\begin{2. Local grayscale correction of the image \(P_{T}\) is conducted according to Equation (19) to enhance the local information of the image. \[x_{out}(i,j)=\left\{\begin{matrix}x_{main}^{HE}(i,j)+(x_{in}(i,j)-x_{main}(i,j)), D_{HE}(i,j)<D_{in}(i,j)\\ x_{HE}(i,j),D_{HE}(i,j)\geq D_{in}(i,j)\end{matrix}\right.\] (19) where \(x_{out}(i,j)\) is the grayscale value of the center pixel of the output image, \(x_{in}(i,j)\) and \(x_{HE}(i,j)\) denote the center pixels of image F and image \(P_{T}\), respectively, and \(x_{main}(i,j)\) and \(x_{min}^{HE}(i,j)\) are the grayscale averages of each pixel in a \(5\times 5\) window centered at \((i,j)\) in the input image and the equalized image, respectively. 3. The final image is the output. Figure 2 shows the effect of image processing and its grayscale histogram during the process of the HE algorithm and AICHE algorithm. It can be seen that although the HE algorithm can improve the image contrast, the image is overexposed due to image stretching. And, after histogram segmentation, the average brightness of the image is protected, but at this point there is still the problem of gray level merging and the loss of image details. After the adaptive local gray level correction of the image, the average brightness of the input image is protected while the contrast and detail information are enhanced, and the image quality is significantly improved.