## 2 Adaptive Piecewise Self-Order Enhancement Algorithm
### Adaptive Piecewise Self-Order Enhancement Algorithm  
In the image gray level enhancement algorithm of the traditional self-ranking algorithm, the image pixel enhancement is mainly based on the maximum interclass difference of the image gray level. In the study of Formula (1) above, it is found that the simple algorithm for the gray level enhancement that adjusts the relevant fixed parameters through prior knowledge uniformly uses a simple normalization to enhance the pixels between the minimum gray level and the maximum gray level. The utilization rate of the interclass gray level information of the image is not high, resulting in a poor image enhancement effect, and the distinction between dark and bright gray levels in the image is polarized. Therefore, in view of the shortcomings of the image enhancement produced by the simple processing in the above formula, this paper constructed a self-order matrix reorganization analysis model to perform an interclass enhancement on the gray levels of the intermediate stage. The image can be enhanced according to different gray intensities, and the gray difference information between each gray level can be fully used to improve the quality of the image after the enhancement. The specific model is as follows:  
\[map(i+1)=\left\{ \begin{array}{l}255\ \,\ \ \ i>\max(R)\\ data\ \,\ \ \ \min(R)\leq i\leq\max(R)\\ 0\ \,\ \ \ i<\min(R)\end{array} \right. \tag{2}\]  
In the formula, \(data[]\) refers to the pixel stored between the minimum pixel and the maximum pixel. Other definitions are as shown in Formula (1). In this operation, all pixels smaller than the minimum and larger than the maximum are defined as 0 and 255 gray levels. For pixels larger than the minimum and smaller than the maximum, the defined reorganization model is as follows:  
\[Data=reshape(data,m,n) \tag{3}\]  
In the formula, \(Data\) represents the pixel matrix after the matrix reorganization of the image gray levels, \(reshape\) represents the element reorganization function, \(data\) represents the result in Formula (2), \((m,n)\) represents the pixel matrix with a size of the element reorganization of \(m\times n\). In order to effectively use the gray level between the minimum value and the maximum value of a pixel to reflect the interclass difference between the graylevels of each pixel and finally realize the gray level enhancement of the pixel, firstly, the histogram analysis of the reconstructed gray pixel is as follows:  
\[DataR=imshist(Data)/(m\times n) \tag{4}\]  
In the formula, \(DataR\) represents the histogram after image normalization, and the other parameters are defined as above. The interclass coefficient of the gray level \(\mu_{T}\) in the histogram can be determined by defining the gray level \(colorlevel=256\) of the pixel according to the image as follows:  
\[\mu_{T}=\mu_{T}+colorlevel(j)\times DataR(j) \tag{5}\]  
In the formula, \(\mu_{T}\) refers to the gray level coefficient in the range from the minimum gray level to the maximum gray level. The initial value is defined as 0, which means the defined gray level is from 1 to 256. In order to achieve the adaptive gray level enhancement, the difference between pixel classes must be adjusted by determining various gray level enhancement parameters \(\mu_{1},\mu_{2},\alpha_{1},\alpha_{2}\) adaptively according to the defined gray level \(colorlevel\). The model for determining each parameter is as follows:  
\[\left\{ \begin{array}{ll}\alpha_{1}=\alpha_{1}+DataR(j_{1})\\ \alpha_{2}=1-\alpha_{1}\end{array} \right. \tag{6}\]  
\[\left\{ \begin{array}{ll}\mu_{1}=\mu_{1}+(j_{2}-1)\times DataR(j_{2})&(j_{2} <Th)\\ \mu_{2}=\mu_{2}+(j_{2}-1)\times DataR(j_{2})&(j_{2}>Th)\\ \mu_{1}=\mu_{1}/\alpha_{1}\\ \mu_{2}=\mu_{2}/\alpha_{2}\end{array} \right.