# Determining Thresholds for Optimal Adaptive Discrete Cosine Transformation
## 2 Materials and Methods
### Proposed Adaptive DCT Algorithm
The first threshold _ps_ (split) determines whether the image fragment should be further split into four quadrants. If the TDV of a fragment is below _ps_, then the tonal distribution of the fragment is supposed to be less uniform, contain more tones and, probably, more details, so it is logical to split it to preserve details after performing a discrete cosine transform. The second threshold _pm_ (mean) determines whether the fragment appears monochromatic enough (if TDV is above _pm_) to be replaced by a single average value of its brightness. The result is the highest possible level of compression since there is only one non-zero DCT coefficient left in the spectrum. Having mean-value tiles does not detract too much from image quality as long as they are small enough not to affect valuable details. For our purposes, it is acceptable to paint unimportant details, like road surface or sky, in solid color, as long as the resulting quality is sufficient. Solid color fragments are demonstrated in \[IMG^{\prime}=\widehat{g}_{pm,ps}(x,y). \tag{2}\]7  
When constructing a quadtree using the abovementioned thresholds, the fragment is first tested with the threshold _pm_ and only then checked for further fragmentation. This means that for each fragment there are three possible outcomes:  
* Replacing with a solid color if its TDV is higher than _pm_;
* Leaving as is if its TDV is between _pm_ and _ps_;
* Splitting into four sub-fragments if its TDV is below _ps_. Tonal distribution variance appeared to be in the range between 1/15 and 1/10 for many of the traffic images in our experiments. Meanwhile, there are cases where completely solid color frames possess a TDV equal to 1. For convenience and visibility, further on we used the inversion of TDV, called ITDV, to display the distribution of frames with more convenient numbers instead of fractions:  
\[IMG^{\prime}=\widehat{g}_{pm,ps}(x,y). \tag{2}\]8  
The majority of the frames are then found in the 10-15 ITDV range. We introduce an optimization process consisting of the following steps: choosing pairs of threshold ADCT values, constructing quadtrees using them, performing discrete cosine  
\[IMG^{\prime}=\widehat{g}_{pm,ps}(x,y). \tag{2}\]9 Example of solid color fragments: (**a**) processed image; (**b**) processed image: solid color fragments are marked with yellow; (**c**) close-ups of the sky and the road surface demonstrate little impact on the overall perception unless zoomed in. transform on their fragments and checking whether the results satisfy certain requirements. The threshold values are optimized for images with various original ITDVs, i.e., the tonal distribution variance is calculated for the entire original image, as we assume it is an acceptable measure of image detail. Optimal thresholds should provide maximum compression efficiency while preserving a certain level of image quality. The example shown in Figure 6 illustrates a quality comparison of compressed images with three distinct levels. For simplicity, the compression ratio is calculated here as a ratio between non-zero DCT coefficients and the total number of coefficients. It does not necessarily portray the actual compression ratio of the stored file, but we consider it sufficiently suitable for this study. Given the appropriate data compression methods for the pixel information, such as run-length encoding, the chosen compression ratio metric allows for good relative comparison between methods. This frees us from the burden of describing a full-scale compression method to implement and measure bits per pixel metric or similar. For example, to compare the performance of ADCT with regular JPEG, one can set appropriate thresholds to split the image into 8 \(\times\) 8 tiles without creating solid color fragments, mimicking regular DCT, and then compare the resulting ratios. The optimization process consists of three levels of optimal value search for the _ps_ and _pm_ thresholds.