# Determining Thresholds for Optimal Adaptive Discrete Cosine Transformation
## 3 Results and Discussion  
To process the experimental data and search for optimal ADCT thresholds, we developed a software implementation of the corresponding algorithm written in C++. The quadtree division algorithm is deterministic by nature because no random values are used, meaning the quadtree will not change if the same parameters and inputs are used. The discrete cosine transform is implemented using the _row-column_ method, which decomposes the original two-dimensional transform into a sequence of two one-dimensional transforms, greatly reducing the complexity of the algorithm. Since the optimization is performed independently for each image in the set, the process can be defined as parallel, allowing parallel computation to be easily implemented using the OpenMP interface and greatly speeding up the calculations. To evaluate the experimental results quantitatively, we define the approximate compression ratio (CR), calculated by the following formula:  
\[CR=\frac{\text{Total Elements Count}}{\text{Non-zero Elements Count}}. \tag{13}\]  
Every fragment of the compressed image consists of a DC (so-called _direct current_) coefficient--the first coefficient responsible for the mean color part of the fragment, practically always the biggest, non-zero AC (_alternating current_) coefficients usually responsible for low cosine frequencies, and zero AC coefficients that have been reduced or rounded to zero, usually those responsible for high frequencies. Removing the high-frequency coefficients leads to losing information on details but also provides most of the compression. The DC coefficient is always present and requires a constant number of bits for encoding, depending on the quantization factor. Zero AC coefficients can be encoded with run-length encoding using the zigzag pattern with just a single number--the number of these zero coefficients. Thus, the amount of non-zero AC coefficients arguably plays the most important role in the resulting bitrate, since it requires a variable amount of encoding instances, unlike the two previous categories of DCT coefficients. Apart from the DC coefficient, the run-length encoding of the zero coefficients and a technique to encode the structure of the quadtree, we consider the ratio between the non-zero coefficients and their total amount a fitting metric to express the quantity of compression. If all the techniques employed in existing algorithms such as JPEG, e.g., Huffman coding, are applied to ADCT,  
Figure 7: Flowchart of the optimization process; the grid is the search area; each grid cell is a pair of threshold values. the resulting bits per pixel metric will mostly depend on the difference between the regular DCT's and the adaptive DCT's compression ratios. As a second quantitative quality metric apart from MS-SSIM, we use peak signal-to-noise ratio (PSNR) for compressed images against the original ones. It is important to note that, since ADCT results in the construction of a quadtree from power-2-sized fragments, the source images must also be power-2-sized or padded to fit into the required dimensions. The optimization results are presented in the figures below, where each subplot corresponds to a certain level of image quality. The results of calculating the optimal threshold values for images with different original ITDVs are shown in Figure 8.  
The resulting distribution for each quality level can be approximated. We tested fitting a linear function and a third-order curve using the least squares method implemented in MATLAB. The threshold searching program was modified to use the resulting threshold functions instead of performing optimization. It outputs MS-SSIM values between the original and compressed image and compares the compression ratios for the linear and the third-order curves. The experimental verification with a test dataset is explained further. As one can see, a decrease in target compression quality not only lowers the thresholds but also creates a gap between them.