# Hybrid Encoding Scheme for AMBTC Compressed Images Using Ternary Representation Technique
## 3 Proposed Method
### Decoding Procedures  
In decoding, data bits are sequentially read and decoded, and image blocks are reconstructed by decoding the read data bits. The detailed steps of decoding are listed as follows:  
* Code stream \(CS_{f}\), block size \(n\times n\), parameter \(\gamma\), \(\sigma\), and cluster size \(k\). * Decompressed image \(I^{\prime}=\left\{I_{i}^{\prime}\right\}_{i=0}^{N-1}\). * Extract \(CS_{A}\) from \(CS_{f}\) and reconstruct \(k\) cluster centers \(\left\{C_{\alpha}\right\}_{\alpha=0}^{k-1}\). * Extract one bit \(b\) from \(CS_{f}\). According to the extracted bit, one of the following decoding cases is then performed:
* If \(b=0_{2}\), the block to be reconstructed is a flat block. All the pixel values of block \(I_{i}^{\prime}\) are the decimal value of the next \(8\) bits extracted from \(CS_{f}\). * If \(b=1_{2}\) and the next extracted bit is \(0_{2}\), the block to be reconstructed is a smooth block. Extract the next \(8\) bits and convert them to a decimal value to obtain the quantized value \(\hat{a}_{s}\). Read the next bit from \(CS_{f}\). If the read bit is \(0_{2}\), \(\hat{b}_{s}\) is reconstructed by the decimal value of the next \(\log_{2}(\gamma)\) bits plus \(\hat{a}_{s}\). Otherwise, \(\hat{b}_{s}\) is reconstructed by the decimal value of next \(\lceil\log_{2}(\sigma)\rceil\) bits plus \(\hat{a}_{s}\). The clustering index \(\alpha_{s}^{s}\) is the decimal value of next \(k\) bits, and the bitmap \(C_{\alpha_{s}^{s}}\) can be obtained from \(\left\{C_{\alpha}\right\}_{\alpha=0}^{k-1}\). Using the AMBTC decoder to decode \(\left\{\hat{a}_{s},\hat{b}_{s},C_{\alpha_{s}^{s}}\right\}\), the image block can be reconstructed. Figure 2: An example of image encoding. * If \(b=1_{2}\) and the next extracted bits is \(1_{2}\), the block to be reconstructed is a complex block. Extract the next 8 bits and convert them to a decimal value to obtain the quantized value \(q_{c}^{0}\). Read the next bit from \(CS_{f}\). If the read bit is \(0_{2}\), \(q_{c}^{1}\) is reconstructed by the \(q_{c}^{0}\) plus the decimal value of the next \(\log_{2}(\gamma)\) bits; otherwise, \(q_{c}^{1}\) is reconstructed by the decimal value of the next \(\lceil\log_{2}(\sigma)\rceil\) bits plus \(q_{c}^{0}\). Using a similar manner, \(q_{c}^{2}\) is reconstructed. To reconstruct the ternary \(\left\{T_{c,j}\right\}_{j=0}^{n\times n-1}\), we start from \(j=0\) to \(j=n\times n-1\) and repeat the following process: Read a bit \(b_{0}\) from \(CS_{f}\). If \(b_{0}=0_{2}\), we have \(T_{c,j}=0\). Otherwise, read the next bit \(b_{1}\) from \(CS_{f}\). If \(b_{0}b_{1}=10_{2}\), \(T_{c,j}=1\). If \(b_{0}b_{1}=11_{2}\), \(T_{i,j}=2\). Once we have \(\left\{q_{c}^{0},q_{c}^{1},q_{c}^{2}\right\}\) and \(\left\{T_{c,j}\right\}_{j=0}^{n\times n-1}\), the \(j\)-th pixel of the image block is reconstructed by \(q_{c}^{0}\), \(q_{c}^{1}\), or \(q_{c}^{2}\) if \(T_{c,j}=0\), 1, or 2, respectively. * Repeat Step 2 until all image blocks are reconstructed, and the final decompressed image \(I^{\prime}\) is obtained. We continue the example given in Section 3.4 to illustrate the decoding process. The detailed process and the decoded result are depicted in Figure 3. To decode the code stream \(CS_{0}=10\mid 00100001\mid 0\ 000101\mid 0101011_{2}\), because the first bit is \(1_{2}\) and the second bit is \(0_{2}\), the to-be-reconstructed block is a smooth block. Extract the next 8 bits from \(CS_{0}\) and convert them into decimal representation; we obtain \(\hat{a}_{0}=33\). The next extracted bit is 0. Therefore, the difference \(d_{0}=5\) is the decimal value of the next \(\log_{2}(\gamma)\) bits, and we have \(\hat{b}_{0}=\hat{a}_{0}+5=38\). Finally, extract \(\log_{2}(k)\) bits and convert them to a decimal value; we have \(\alpha_{s}^{*}=43\) and the bitmap \(C_{43}\) is obtained. The image block can then be constructed by decoding \(\left\{\hat{a}_{0},\hat{b}_{0},C_{43}\right\}\) using the AMBC decompression technique.