# Dual Histogram Equalization Algorithm Based on Adaptive Image Correction
## 3 Proposed AICHE Transformation
### Histogram Segmentation  
For most images, the distribution of pixel grayscale is not uniform, and the average brightness of the image will be shifted during the equalization process. This can be solved using histogram segmentation. When segmenting the grayscale histogram, if the segmented sub-histogram is too narrow, the equalization effect of the image will be reduced, and if it is too wide, it will lead to excessive enhancement and the loss of details. Therefore, the selection of the threshold value is extremely important, and the improper selection of the threshold value will directly lead to the degradation of the image quality after equalization.  
First, suppose a threshold t is the segmentation point, and the image is divided into target region A and background region B according to the gray level, where region A consists of pixels with gray value in the interval \([MIN,t]\), and region B consists of pixels with gray value in the interval \([t+1,MAX]\). Then, the ratio of class A to class B \(q_{A}(t)\), \(q_{B}(t)\) is  
\[q_{A}(t)=\sum_{i=MIN}^{t}PDF(i),q_{B}(t)=\sum_{i=T+1}^{MAX}PDF(i) \tag{4}\]  
where \(MIN\) and \(MAX\) denote the initial and termination values of the histogram, respectively, and \(P(i)\) denotes the probability that the grayscale value is \(i\).  
\(\mu_{A}(t)\) and \(\mu_{B}(t)\), can be calculated as follows:  
\[\mu_{A}(t)=\sum_{i=MIN}^{t}\frac{iPDF(i)}{q_{A}(t)},\mu_{B}(t)=\sum_{i=T+1}^{ MAX}\frac{iPDF(i)}{q_{B}(t)} \tag{5}\]  
where \(\mu_{A}(t)\) and \(\mu_{B}(t)\) denote the probabilities of class A and class B, respectively.  
Then, the \(\mu\) can be calculated as follows:  
\[\mu=q_{A}(t)\mu_{A}(t)+q_{B}(t)\mu_{B}(t) \tag{6}\]  
where \(\mu\) is the average grayscale of the input image.  
The inter-class variance \(\sigma_{T}^{2}\) is defined as  
\[\sigma_{T}^{2}=q_{A}(t)[\mu_{A}(t)-\mu]^{2}+q_{B}(t)[\mu_{B}(t)-\mu]^{2} \tag{7}\]  
The traditional Otsu algorithm is simple, convenient, and not affected by the brightness of the image. It sets the threshold at which the variance between the target and background grayscale reaches its maximum value as the optimal segmentation threshold: \(K_{Otsu}=\arg_{t}\min\sigma_{T}^{2}\). The smaller the distance between each pixel in two regions and the class center, the better the pixel cohesion in each region. The traditional Otsu algorithm  
Figure 1: Overall flowchart of AICHE algorithm.  
is less effective in segmentation because it does not consider pixel spatial correlation. To measure the goodness of pixel cohesion, \(d^{2}(t)\) is assumed and calculated as follows:  
\[d^{2}(t)=\left(\mu_{A}(t)-\mu_{B}(t)\right)^{2} \tag{8}\]  
where \(d^{2}(t)\) is a distance metric. \(\sigma_{A}^{2}\) and \(\sigma_{B}^{2}\) are calculated as follows:  
\[\sigma_{A}^{2}(t)=\frac{1}{q_{A}(t)}\sum_{i=MIN}^{t}{(i-\mu_{A}(t))^{2}P(i)} \tag{9}\]  
\[\sigma_{B}^{2}(t)=\frac{1}{q_{B}(t)}\sum_{i=t+1}^{MAX}{(i-\mu_{B}(t))^{2}P(i)} \tag{10}\]  
where \(\sigma_{A}^{2}\) and \(\sigma_{B}^{2}\) denote the mean variance values of the target and background regions, respectively.  
Obviously, the smaller the average variances \(\sigma_{A}^{2}\) and \(\sigma_{B}^{2}\), the better the segmentation effect; on this basis, a new threshold-finding formula \(G(t)\) is obtained.  
\[G(t)=\frac{q_{A}(t)q_{B}(t)d^{2}(t)}{\sigma_{A}^{2}(t)+\sigma_{B}^{2}(t)}= \frac{q_{A}(t)q_{B}(t)(\mu_{A}(t)-\mu_{B}(t))^{2}}{\sigma_{A}^{2}(t)+\sigma_{ B}^{2}(t)} \tag{11}\]  
The corresponding \(t\) when \(G(t)\) takes the maximum value is the optimal threshold. Therefore, \(K_{out}\) is obtained as follows:  
\[K_{out}=\text{arg}_{t}\text{max}G(t) \tag{12}\]  
where \(K_{out}\) is the optimal threshold value.  
According to threshold \(K_{out}\), the histogram is divided into two sub-histograms, where the first part is defined as \(i\in[0:K_{out}]\) and the second part is defined as \(i\in(K_{out}+1:L)\).