In addition to the previously mentioned multi-context encoding methods (MED, GAP, GAP
+), new proposals with varying numbers of contexts have continued to emerge over the years; examples include works from 2001–2006 [
39,
40,
45,
46,
47] as well as slightly more recent ones [
48,
49,
50,
51,
52,
53]. These methods offer the low computational complexity of both the encoder and the decoder together with relatively high compression efficiency. A common feature is a relatively small number of contexts, and their efficiency is typically comparable to that of GAP
+ and GBSW
+.
Compared to the methods described in
Section 2.3, our Multi-ctx2 method proposed in this section incorporates several improvements to objective function minimization and multi-context partitioning. The proposed solution involves two stages. First, to ensure that the method is considered universal for a relatively broad class of images, the preliminary training stage is based on a training image database, resulting in five sets of predictive models with 3456 or 4096 contexts. This stage uses the IRLS method for fast minimization of the absolute error [
24]. The training stage needs to be performed only once and is similar to deep neural network training. The training image database should be as diverse as possible in terms of features (smooth, edge-rich, and textured image fragments). In our research, we used 55 training images, which combined with eight lossless rotation phases (every 90 degrees and mirror reflections) yielded a total of 440 training images. None of the test images used in
Section 3.5 to evaluate performance were part of the training image set.
After the training process, each set consists of a group of 3456 or 4096 14th-order predictive models, which are used to predict values based on the obtained context number and the method used to determine it. Each coefficient is stored in a dictionary with a fractional precision of 10 bits.
3.1. Components of the Proposed Codec
The solution proposed in this paper is based on a cascaded approach (see
Figure 3). In addition to the predicted value calculated using the authors’ context-dependent linear prediction, the Context-Dependent Constant Component Removing (CDCCR) block (similar to codecs such as CALIC or JPEG-LS) discussed in
Section 3.4 is used to remove the constant component
associated with a specific context. The final blocks of the cascade are used to efficiently encode prediction errors
using an adaptive Golomb encoder and a context-dependent adaptive binary arithmetic encoder.
The first block uses context-dependent linear prediction. When encoding each successive pixel, five context numbers (
) are computed according to the rules in
Section 3.1. Each number serves as an index into the corresponding table, which contains models with
linear prediction coefficients
. The final predicted value is computed using the formula
where the vector
contains the values of the twelve nearest neighbors of pixel
(see
Figure 1) as well as the two predicted values
and
determined as described in
Section 2.3.1 and
Section 2.3.2, respectively. Using Equation (9) to compute the predicted value has lower computational complexity than modern deep learning-based methods.
The second data processing block removes the constant component associated with a given context (details are provided in
Section 3.5). The data processing flowchart for the first two blocks is shown in
Figure 4, where CTX
n is the block for determining the
nth context number, DICT
n is the dictionary of prediction coefficients for the
nth model, and PRED
n is the block for calculating the value of the
nth predictor. The last two blocks, shown in
Figure 3 and used for encoding prediction errors, are described in detail in [
54].
Algorithms 3 and 4, presented below, illustrate the data processing procedures in the encoder and decoder, respectively, of the solution proposed in this paper.
| Algorithm 3 The data processing process in the encoder. |
- 1:
For each encoded pixel : - 2:
Determine numbers of the 5 types of contexts according to the rules described in Section 3.3. - 3:
Calculate the predicted value (Equation (9)) and the prediction error (Equation (12)) after accounting for the context-dependent constant . - 4:
Convert the prediction error into a bitstream using the adaptive Golomb coder. - 5:
Encode the bit sequence from step 4 using an adaptive binary arithmetic encoder. - 6:
Return to step 2 if there are still pixels to encode.
|
| Algorithm 4 The data processing process in the decoder. |
- 1:
For each decoded pixel : - 2:
Decode the input bit sequence using an adaptive binary arithmetic coder to obtain a Golomb code word. - 3:
Convert the Golomb words to the form of prediction error . - 4:
Determine numbers of the 5 types of contexts according to the rules described in Section 3.3. - 5:
Calculate the predicted value (using Equation (9)) and , and then add these values to to obtain the decoded pixel value . - 6:
Return to step 2 if there are still pixels to decode.
|
It is worth noting that the solution proposed here can also be used in a near-lossless mode by setting a maximum allowable error d, i.e., the difference between the original color value and the decoded value.
3.2. Context Segmentation Main Function Set
The proposed solution uses three methods to determine the context number, two of which are applied twice by substituting different values for the parameter representing the initial predicted value
of the currently encoded pixel
. Two simple methods for determining the predicted value were used for this purpose, namely, the GAP
+ method (see
Section 2.3.1) and the GBSW
+ method (see
Section 2.3.2), yielding five different predicted values for the currently encoded pixel
. Their arithmetical mean serves as the basis for the formula for determining the final predicted value.
By analogy with neural networks, the prediction method in Multi-ctx2 can be viewed as a simplified MLP network with a single hidden layer. At the input, we have twelve neighborhood pixels and two predicted values: GAP+ and GBSW+ (input layer). The hidden layer comprises five methods for determining the predicted value. The output layer consists of a single neuron that aggregates values from the hidden layer using an arithmetical mean (activation function ReLU, similar to hidden layer). Unlike MLP, in Multi-ctx2 it is possible to perform simple calculations in fixed-point format and omit the exponential function, which is a practical advantage for hardware implementation.
The context number is generated by combining decisions from various scalar quantizers (two-state or multi-state) based on the immediate neighborhood of the currently encoded pixel . In this way, we obtain a set of features from the nearest neighborhood viewed from multiple perspectives, including the dependencies of the pixel surroundings relative to the initial predicted value . This is an input parameter, and two possibilities are considered here: , used when calculating contexts 1 and 2, or , used when calculating contexts 4 and 5. Most decision rules are based on two-state quantizers that return a bit value of 0 or 1 (individual bits are denoted here as ), indicating whether a specific condition is satisfied (YES/NO). Since the decision rules partially overlap across the different methods of constructing the context number, they are listed collectively here:
—condition for
—condition
—condition
—condition
, where:
—condition
—condition .
3.3. Setting the Context Number
This section discusses methods for determining the five types of contexts. The context number for type 1 is largely based on the nearest-neighbor relationship with respect to
. It is a 12-bit number of the form
, where
for
. The last two bits,
, are computed using a four-level quantizer for the variance
with three thresholds
, where
and
. Context 4 is defined in exactly the same way but with
instead of
.
The context number of type 2 is a 12-bit number of the form , where the first eight bits are as follows: for and for . The last four bits are computed from four binary quantizers, with value 1 (or 0) when the condition is satisfied (or not satisfied) for . Type 5 context is determined identically but using instead of used in the case of type 2 context.
For contexts 1 and 2 (and their type 4 and 5 counterparts), there are distinct context numbers; in contrast, context type 3 allows the context number to be chosen from 0 to 3455.
The first step in determining the number of the context type 3 is to calculate the three differences , , . We quantize each of them (using a six-state quantizer that returns the interval number as an integer from 0 to 5) with the thresholds , which correspond to the quantized value of labeled as follows: large negative, medium negative, small negative, small positive, medium positive, and large positive. With three integers from the range 0 to 5, we obtain possible states, which when combined with the four-bit number gives a total of numbers of the third context type.
3.4. Method for Correcting Cumulative Prediction Errors
In many cases, prediction methods may exhibit a constant component in the calculated errors, the nature of which depends on the characteristics of the given context. For this reason, many solutions propose using an adaptive method to remove the constant component (bias cancellation), also known as context-specific prediction error correction, thereby improving the efficiency of predictive modeling.
Adaptive methods for removing the constant component are used in CALIC and JPEG-LS, among others. For each context, the number of occurrences and the cumulative sum of prediction errors are tracked in real time and the current estimate of the prediction error is corrected based on these values [
11]. The proposed solution employs a similar approach, with the context number determined as in the type-1 context described in
Section 3.2, except that to reduce the number of contexts to 2048, we do not use the most significant bit
. Additionally, for the smallest images with no more than
pixels, we reduce the number of contexts to 1024 (also omitting the
bit). This is because the cumulative prediction error is calculated adaptively for each
ith context, and a large number of contexts slows the calculation of the correct approximate value of
. Initially, the counts
of occurrences of the
ith context are set to 4, while the sum of prediction errors
is set to 0. During encoding, the cumulative sum of prediction errors for the
ith context is updated for each subsequent pixel:
, and the size
of that context is incremented by 1. The value of the constant term
is added to the predicted value computed using Equation (9). After rounding the result to the nearest integer, we obtain the final prediction error:
which undergoes two-stage encoding using the adaptive Golomb code followed by the context-dependent adaptive binary arithmetic code CABAC; this stage is described in detail in [
54].
3.5. Efficiency Analysis of an Improved Multi-Context Method
In the proposed method, we use the arithmetical mean of five predictive models as the predicted value; each model is associated with one of the five context types. To demonstrate the efficiency of each of the five approaches, we calculate the average bit rate for a set of 45 test images [
55] independent of the training image set (see
Table 4) based on a single prediction model indicated by the
ith context number assignment type (labeling the columns as
K-i for
). Additionally, the table includes results obtained using other fast prediction methods (
,
, and
) known from the literature, as described in
Section 2.3. These were substituted into our Multi-ctx2 codec at the prediction-error estimation stage for the purposes of the experiment.
Table 5 compares the average bit rates of several well-known fast lossless image compression methods from the literature. The averaged results for a standard set of nine test images at a resolution of
show that the Multi-ctx2 method offers the lowest average bit rate, outperforming even the ALCM
+ method, which uses a content-optimized linear predictor of order
. In turn,
Table 6 presents results for several of the latest classical lossless image compression methods as well as those based on deep learning (LCIC, L3C, CWPLIC, LCIC duplex). The proposed solution demonstrated the lowest average bit rate in the vast majority of cases, with an average improvement over JPEG-LS of 6.85% and 7.03%, respectively, for both sets of test images in lossless mode. The results in these tables confirm the effectiveness of the proposed solution.
This also confirms the notion that among widely available non-deep learning codecs, the best results are achieved with JPEG-XL in high-efficiency mode (switch “
–distance=0 –effort=9”) as opposed to its default settings. This mode requires longer encoding times than the default settings. The situation is similar for WebP, where the encoding time for a 512 × 512—pixel image is just 0.144 s with the default settings. However, if we run this codec in the highest-performance mode (with the switches “
-lossless -m 6 -q 100 -quiet”), the encoding time increases to 4.058 s (all time measurements presented in this paper were performed using a i5 3.4 GHz processor). Therefore,
Table 7 presents the results for these specific codecs, using a set of 45 test images. These include not only photos from digital cameras but also images representing other specialized categories. Both
Table 7 and
Table 8 include a comparison with the H.266 codec, which is designed for video stream compression and is implemented using the VTM reference software for VVC with a set of switches that enable lossless compression.
A detailed list of ten sample images from other categories is provided in
Table 8. The images labeled Airfield and Aerial were acquired using methods typical of remote sensing, while the image labeled Earth belongs to the space imaging category. Other specific images include Seismic and Finger, which contain seismic data and fingerprints, respectively. The next two images, Shapes and Noisesqare, are computer-generated; the first has smooth tonal transitions, while the second was generated with a high level of added noise. Among the images in the natural photography category, the image labeled Barb was selected as a specific example of images containing certain textured areas. Recently, there has also been a need to archive photographs of human silhouettes without elaborate backgrounds for the purposes of customizable virtual dressing; this category is represented by the images Ronaldo and Lakers24. It was mainly due to these last two images in the list from
Table 8 that Multi-ctx2 ended up in third place. Nevertheless, it outperformed WebP in seven out of ten cases and JPEG-XL in half of the cases. This highlights a drawback of single-pass solutions (without selecting from many compression algorithms) based on pretraining. The problem can be partially solved by further expanding the training image dataset. On the other hand, the proposed solution offers higher efficiency than the CNN 2023 [
56] method based on a cellular neural network, where the pretraining process took two months and the encoding and decoding time for an image is more than twenty times longer than in the case of Multi-ctx2.
Table 5.
Results of bit averages for a set of standard test images.
Table 5.
Results of bit averages for a set of standard test images.
| Image | JPEG-LS [57] | CALIC [18] | Blend-7 [29] | HBB [58] | Multi-ctx [59] | ALCM+ [60] | Multi-ctx2 |
|---|
| Balloon | 2.889 | 2.78 | 2.84 | 2.80 | 2.727 | 2.733 | 2.675 |
| Barb | 4.690 | 4.31 | 4.43 | 4.28 | 4.243 | 4.211 | 4.185 |
| Barb2 | 4.684 | 4.46 | 4.57 | 4.48 | 4.421 | 4.401 | 4.386 |
| Board | 3.674 | 3.51 | 3.57 | 3.54 | 3.467 | 3.425 | 3.415 |
| Boats | 3.930 | 3.78 | 3.84 | 3.80 | 3.730 | 3.696 | 3.683 |
| Girl | 3.922 | 3.72 | 3.76 | 3.74 | 3.664 | 3.612 | 3.599 |
| Gold | 4.475 | 4.35 | 4.42 | 4.37 | 4.310 | 4.293 | 4.288 |
| Hotel | 4.378 | 4.18 | 4.29 | 4.27 | 4.171 | 4.169 | 4.128 |
| Zelda | 3.884 | 3.69 | 3.79 | 3.72 | 3.700 | 3.598 | 3.658 |
| Average | 4.058 | 3.864 | 3.946 | 3.889 | 3.826 | 3.793 | 3.780 |
Table 6.
Results of bit averages for the second set of test images based on experiments in [
22].
Table 6.
Results of bit averages for the second set of test images based on experiments in [
22].
| Image | BPG | PNG | LCIC | JPEG 2000 | JPLEG-LS | JPEG-XL | FLIF | WebP | L3C | CWPLIC | LCIC Duplex | Multi-ctx2 |
|---|
| Airplane | 4.32 | 4.26 | 3.99 | 4.00 | 3.80 | 3.71 | 3.82 | 3.87 | 4.56 | 3.69 | 3.69 | 3.572 |
| Barbara | 5.06 | 5.22 | 4.61 | 4.61 | 4.70 | 4.40 | 4.56 | 4.55 | 5.44 | 4.35 | 4.36 | 4.187 |
| Coastg. | 5.70 | 5.06 | 4.82 | 4.83 | 4.86 | 4.73 | 4.93 | 4.81 | 5.82 | 4.80 | 4.83 | 4.576 |
| Comic | 6.15 | 5.84 | 5.63 | 5.65 | 5.30 | 5.07 | 5.50 | 5.45 | 6.60 | 4.83 | 4.83 | 4.800 |
| Flowers | 5.18 | 5.08 | 4.91 | 4.92 | 4.62 | 4.51 | 4.74 | 4.76 | 5.53 | 4.41 | 4.35 | 4.320 |
| Goldhill | 4.95 | 4.70 | 4.58 | 4.59 | 4.43 | 4.37 | 4.50 | 4.47 | 5.27 | 4.33 | 4.33 | 4.203 |
| Lennagr. | 4.54 | 4.61 | 4.31 | 4.31 | 4.24 | 4.16 | 4.28 | 4.14 | 4.95 | 4.13 | 4.08 | 3.969 |
| Mandrill | 6.61 | 6.23 | 6.11 | 6.11 | 6.04 | 5.98 | 6.14 | 5.89 | 6.97 | 5.95 | 5.89 | 5.766 |
| Monarch | 4.10 | 4.26 | 3.82 | 3.82 | 3.70 | 3.54 | 3.68 | 3.73 | 4.37 | 3.40 | 3.45 | 3.388 |
| Pepper | 4.77 | 4.90 | 4.63 | 4.63 | 4.51 | 4.48 | 4.58 | 4.50 | 5.38 | 4.67 | 4.38 | 4.299 |
| Ppt3 | 2.20 | 2.35 | 2.41 | 2.41 | 2.04 | 1.84 | 1.87 | 2.06 | 3.71 | 2.14 | 2.07 | 1.735 |
| Zebra | 5.83 | 5.19 | 4.89 | 4.89 | 4.81 | 4.66 | 4.84 | 4.86 | 6.08 | 4.65 | 4.68 | 4.504 |
| Average | 4.951 | 4.808 | 4.559 | 4.564 | 4.421 | 4.288 | 4.453 | 4.424 | 5.390 | 4.279 | 4.245 | 4.110 |
Table 7.
Measurement of bit averages for a set of 45 standard test images.
Table 7.
Measurement of bit averages for a set of 45 standard test images.
| PNG | H.266 | WebP | JPEG-XL | Multi-ctx2 |
|---|
| 4.719 | 4.505 | 4.216 | 4.123 | 4.037 |
Table 8.
Measurement of bit averages for images across different categories.
Table 8.
Measurement of bit averages for images across different categories.
| Image | PNG | H.266 | WebP | JPEG-XL | Multi-ctx2 |
|---|
| Airfield | 5.824 | 5.741 | 5.086 | 4.918 | 4.841 |
| Aerial | 5.414 | 5.079 | 5.075 | 4.725 | 4.556 |
| Earth | 3.369 | 3.243 | 2.933 | 2.832 | 2.796 |
| Seismic | 3.139 | 3.185 | 2.954 | 2.734 | 2.661 |
| Finger | 5.817 | 6.270 | 5.564 | 5.324 | 5.342 |
| Shapes | 1.177 | 0.951 | 1.015 | 0.708 | 0.973 |
| Noisesquare | 5.755 | 5.664 | 5.085 | 5.245 | 5.269 |
| Barb | 5.213 | 4.644 | 4.550 | 4.271 | 4.185 |
| Ronaldo | 2.779 | 5.037 | 2.510 | 2.236 | 3.980 |
| Lakers24 | 2.684 | 5.358 | 2.486 | 2.041 | 3.534 |
| Average | 4.117 | 4.517 | 3.726 | 3.503 | 3.814 |
In addition, the test images from the “Customizable Virtual Dressing” category are characterized by an unusual probability distribution (a small number of colors, resulting from preprocessing the photos using dithering, which introduces slight artificial noise into what was originally a fairly smooth background). For this reason, combining the Golomb code with CABAC without initial parameter tuning was ineffective at compressing prediction errors (WebP and JPEG-XL in high-performance mode support such tuning, which comes at a significant additional cost in terms of increased encoding time).
The following tables pertain to the near-lossless mode.
Table 9 compares average bit rates and PSNR values for several methods from the literature, using the
Lennagrey image as an example.
Table 10 compares the results of LOCO-I and an extension of the TMW method to the near-lossless mode [
61] (which has high implementation complexity in the encoding stage) with the Multi-ctx2 method proposed in this work for permissible error values
and
. A much broader comparison set was compiled for
(see
Table 11). On average, the proposed method produced files that were 10.2% shorter than JPEG-LS at the given error threshold.
Table 9.
Comparison of bit averages and PSNR values for the Lennagrey image.
Table 9.
Comparison of bit averages and PSNR values for the Lennagrey image.
| Method | | | |
|---|
|
BPP
|
PSNR
|
BPP
|
PSNR
|
BPP
|
PSNR
|
|---|
| JPEG-LS | 4.24 |
∞
| 2.72 | 49.90 | 2.09 | 45.15 |
| CALIC | 4.11 |
∞
| 2.59 | 49.89 | 1.95 | 45.16 |
| Vavelet [62] | 4.30 |
∞
| 2.77 | 49.89 | 2.12 | 45.17 |
| Two-stage [63] | 3.99 |
∞
| 2.47 | 49.90 | 1.89 | 45.15 |
| Multi-ctx2 | 3.969 |
∞
| 2.458 | 49.89 | 1.824 | 45.17 |
Table 10.
Comparison of bit averages for the acceptable error value .
Table 10.
Comparison of bit averages for the acceptable error value .
| Image | | |
|---|
|
LOCO-I v.0.90N
|
TMW (Mode 3)
|
Multi-ctx2
|
LOCO-I v.0.90N
|
TMW (Mode 3)
|
Multi-ctx2
|
|---|
| Bridge256 | 3.49 | 3.38 | 3.290 | 1.73 | 1.63 | 1.547 |
| Camera256 | 2.28 | 2.08 | 1.964 | 0.96 | 0.90 | 0.726 |
| Couple256 | 1.82 | 1.60 | 1.536 | 0.86 | 0.70 | 0.503 |
| Airplane | 1.84 | 1.64 | 1.563 | 0.72 | 0.57 | 0.466 |
| Baboon | 3.72 | 3.49 | 3.468 | 1.91 | 1.68 | 1.645 |
| Lennagrey | 2.09 | 1.83 | 1.821 | 0.93 | 0.55 | 0.485 |
| Peppers | 2.29 | 2.09 | 2.086 | 0.93 | 0.64 | 0.541 |
| Shapes | 0.79 | 0.75 | 0.545 | 0.47 | 0.58 | 0.248 |
| Balloon | 1.242 | 0.90 | 0.824 | 0.49 | 0.32 | 0.149 |
| Boats | 1.902 | 1.65 | 1.608 | 0.78 | 0.66 | 0.496 |
| Gold | 2.333 | 2.19 | 2.138 | 0.99 | 0.81 | 0.695 |
| Average | 2.163 | 1.964 | 1.895 | 0.979 | 0.822 | 0.682 |
Table 11.
Comparison of bit averages for the acceptable error value .
Table 11.
Comparison of bit averages for the acceptable error value .
| Image | JPEG-LS [10] | Sunset [23] | BAROLTO [23] | ASBOSC [64] | CALIC [18] | Multi-ctx2 |
|---|
| Balloon | 1.465 | 1.45 | 1.48 | 1.457 | 1.461 | 1.346 |
| Barb1 | 3.149 | 3.10 | 2.88 | 2.868 | 2.837 | 2.684 |
| Barb2 | 3.174 | 3.17 | 3.06 | 3.012 | 2.986 | 2.892 |
| Board | 2.203 | 2.22 | 2.09 | 2.033 | 2.038 | 1.951 |
| Boats | 2.478 | 2.48 | 2.39 | 2.306 | 2.315 | 2.217 |
| Girl | 2.446 | 2.38 | 2.28 | 2.258 | 2.250 | 2.137 |
| Gold | 2.996 | 3.06 | 2.92 | 2.904 | 2.874 | 2.790 |
| Hotel | 2.873 | 2.94 | 2.75 | 2.719 | 2.697 | 2.615 |
| Zelda | 2.375 | 2.26 | 2.25 | 2.221 | 2.225 | 2.161 |
| Average | 2.573 | 2.56 | 2.46 | 2.420 | 2.409 | 2.310 |