# A Low-Complexity Lossless Compression Method Based on a Code Table for Infrared Images
## 4 Proposed Method
### The Creation and Coding of General Code Table
#### 4.1.2 Canonical Huffman Coding Based on General Code Table  
For the compression of multi-frame images or large panoramic image datasets, we need to count several times to obtain the frequency table of each frame before constructing the Huffman tree, which will seriously affect the compression speed. In Section 3, we learn that the probability distribution of differential pixels follows a certain pattern and approximately adheres to a Laplace distribution. Therefore, through extensive experimentation, a differential pixel probability distribution model suitable for most scenarios can be statistically derived. This model can then be used to generate a code table based on Huffman coding rules.  
We select the 53 images mentioned earlier and count the frequency of occurrence of differential pixels. The partial images are shown in Figure 3. We calculate the total probability of pixels occurring within the boundary, all with absolute values smaller than that of the boundary pixel. The cumulative probability of boundary pixels having values less than 150 exceeds 0.99 as shown in Figure 4. Thus, the differential pixels are limited to [\(-\)150, +151] to create a general code table for broad application. In total, there are 302 points ranging from \(-\)150 to 151. We sort the differential pixels by frequency and plot the first 302 points with the highest probability of occurrence as shown in Figure 5.  
The mean probability distribution of the 53 images serves as a model for most scenes as shown in Figure 5. The Huffman tree is constructed from the average probability distribution model to obtain the general code table: \(\vec{C}\) = [0 1 0 4 8 7 7 7 8 15 23 32 36 43 44 53 14]. The \(\vec{C}\) has a total of 302 codes. Each pixel symbol in the differential pixel range [\(-\)150, +151] has one-to-one mapped code.  
Create an array \(\vec{S}\) to record the code values and lengths in order from the smallest to the largest code value. The pixel values have the following correspondence with the \(\vec{S}\) element index:  
\[index=\begin{cases}2\times(0-pixel),&\text{if }pixel\leq 0\\ 2\times pixel-1,&\text{otherwise}.\end{cases}, \tag{6}\]  
The probability distribution of the difference image pixels is essentially symmetric around zero. The probability of a difference pixel being \(+pixel\) (\(pixel\) \(>\) 0) is approximately equal to that of \(-pixel\). In Huffman coding, a probability model that ranks probabilities  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Pixel** & **Frequency** & **Code Length** & **Code Value** & **Code** \\ \hline
0 & 106,708 & 2 & 0 & 00 \\ \(-\)1 & 19,885 & 4 & 4 & 0100 \\
1 & 17,535 & 4 & 5 & 0101 \\ \(-\)2 & 17,124 & 4 & 6 & 0110 \\
2 & 14,818 & 4 & 7 & 0111 \\ \(-\)3 & 14,253 & 4 & 8 & 1000 \\
3 & 12,135 & 5 & 18 & 10010 \\... &... &... &... &... \\ \hline \hline \end{tabular  
For a 14-bit image, there is a possibility that the number of symbols is more than 302, so longer codes are required. However constructing long codes can negatively impact both the compression efficiency and speed. Considering the practical situation, differential pixels are concentrated in small ranges, and pixels beyond the range occur infrequently but inevitably. The \(\vec{C}\) is very difficult to apply. So an improved Huffman coding lossless compression algorithm is proposed.