*2.5. k*2*-Raster*

*k*2-raster is a compact data structure that allows us to store raster pixels in reduced space. It consists of several basic components: bitmaps, DACs and LOUDS. Similar to a *k*2-tree, the image matrix is partitioned recursively until each subquadrant is of size *k*2. The resulting LOUDS tree topology contains the bitmap *T* where the elements are accessed with the rank function. Unlike *k*2-tree, at each tree level, the maximum and minimum values of each subquadrant are stored in two bitmaps which are respectively called *Vmax* and *Vmin*. However, to compress the structure further, the maximum and minimum values of each level are compared with the corresponding values of the parent and their differences will replace the stored values in the *Vmax* and *Vmin* bitmaps. The rationale behind all this is to obtain smaller values for each node so as to get a better compression with DACs. An example of a simple 8 × 8 matrix is given to illustrate this point in Figure 9. A *<sup>k</sup>*2-raster is constructed from this matrix with maximum and minimum values stored in each node in Figure 10. The structure is further modified, according to the above discussion, to form a tree with smaller maximum and minimum values and this is shown in Figure 11.

Next, with the exception of the root node at the top level, the *Vmax* and *Vmin* bitmaps at all levels are concatenated to form *Lmax* and *Lmin* bitmaps. The root's maximum (*rMax*) and minimum (*rMin*) values are integer values and will remain uncompressed.

For an image of size *<sup>n</sup>* × *<sup>n</sup>* with *<sup>n</sup>* bands, the time complexity to build all the *<sup>k</sup>*2-rasters is O(*n*3) [22]. To query a cell from the structure, which has a tree height of at most log*<sup>k</sup> <sup>n</sup>* levels, the time complexity to extract a codeword at a single *Lmax* level is O(log*<sup>k</sup> n*), and this is the worst-case time to traverse from the root node to the last level of the structure. The number of levels, L, in *Lmax* can be obtained from the maxinum integer in the sequence and with this, we can compute the time complexity for a cell query, which is O(log*<sup>k</sup> n* · L) [23,25].

To sum up, a *k*2-raster structure is composed of a bitmap *T*, a maximum bitmap *Lmax*, a minimum bitmap *Lmin*, a root maximum *rMax* integer value and a root minimum *rMin* integer value.

**Figure 9.** An example of an 8 <sup>×</sup> 8 matrix for *<sup>k</sup>*2-raster. The matrix is recursively partitioned into square subquadrants of equal size. During the process, unless all the cells in a subquadrant have the same value, the partitioning will continue. Otherwise the partitioning of this particular subquadrant will end at this point.

**Figure 10.** A *k*2-raster (*k* = 2) tree storing the maximum and mininum values for each quadrant of every recursive subdivision of the matrix in Figure 9. Every node contains the maximum and minimum values of the subquadrant, separated by a dash. On the last level, only one value is shown as each subquadrant contains only one cell.

**Figure 11.** Based on the tree in Figure 10, the maximum value of each node is subtracted from that of its parent while the minimum value of the parent is subtracted from the node's minimum value. These differences will replace their corresponding values in the node. The maximum and minimum values of the root remain the same.

#### *2.6. Predictive Method*

As mentioned in the Introduction, an interband predictor called 3D-CALIC was proposed by Wu et al. in 2000 and another predictor called M-CALIC by Magli et al. in 2004. Our predictor is based on the idea of least squares method and the use of reference bands that were discussed in both the 3D-CALIC [14] and M-CALIC [15] papers. Consider two neighboring or close neighboring bands of the same hyperspectral image. These bands can be represented by two vectors **X** = (*x*1, *x*2, *x*3, ..., *xn*−1, *xn*) and **Y** = (*y*1, *y*2, *y*3, ..., *yn*−1, *yn*) where *xi* and *yi* are two pixels that are located at the same spatial position but in different bands, and *n* is the number of pixels in each band. We can then employ the close similarity between the bands to predict the pixel value in the current band **Y** using the corresponding pixel value in band **X**, which we designate as the reference band.

A predictor for a particular band can be built from the linear equation:

$$
\hat{\mathbf{Y}} = \mathbf{a}\mathbf{X} + \boldsymbol{\beta} \tag{1}
$$

so as to minimize ||**Yˆ** <sup>−</sup> **<sup>Y</sup>**||<sup>2</sup> <sup>2</sup> where **Yˆ** is the predicted value and **<sup>Y</sup>** is the actual value of the current band. The optimal values for *α* and *β* should minimize the prediction error of the current pixel and can be obtained by using the least squares solution:

$$\hat{\mathbf{x}} = \frac{n\sum\_{i=1}^{n} \mathbf{x}\_{i} y\_{i} - \sum\_{i=1}^{n} \mathbf{x}\_{i} \sum\_{i=1}^{n} y\_{i}}{n\sum\_{i=1}^{n} \mathbf{x}\_{i}^{2} - (\sum\_{i=1}^{n} \mathbf{x}\_{i})^{2}},\tag{2}$$

$$\beta = \frac{n\sum\_{i=1}^{n} y\_i - \text{ ft}\sum\_{i=1}^{n} x\_i}{n} \tag{3}$$

where *n* is the size of each band, i.e., the height multiplied by the width, *α*ˆ the optimal value of *α* and *β*ˆ the optimal value of *β*.

The difference between the actual and predicted pixel values of a band is known as the residual value or the prediction error. When all the pixel values in the current band are calculated, these prediction residuals will be saved in a vector, which will later be used as input to a *k*2-raster.

In other words, for a particular pixel in the current band and the corresponding pixel in the reference band, *δ<sup>i</sup>* being the residual value, *yi* the actual value of the current band, and *xi* the value of the reference band, to encode, the following equation is used:

$$
\delta\_{\hat{i}} = y\_{\hat{i}} - \left(\mathbb{A} \cdot \mathbf{x}\_{\hat{i}} + \hat{\beta}\right) \,. \tag{4}
$$

To decode, the following equation is used:

$$y\_i = \delta\_i + (\mathfrak{a} \cdot \mathfrak{x}\_i + \mathfrak{z}) \,. \tag{5}$$

The distance from the reference band affects the residual values. The closer the current band is to the reference band, the smaller the residual values would tend to be. We can arrange the bands into groups. For example, the first band can be chosen as the reference and the second, third and fourth bands will have their residual values calculated with respect to the first band. And the next group starts with the fifth band as the reference band, etc.

For this coding method, the group size (stored as a 2-byte short integer) as well as the *α*ˆ and *β*ˆ values for each band (stored as 8-byte double's) will need to be saved for use in both the encoder and the decoder. Note that the size of these extra data is insignificant - which generally comes to around 3.5 kB - compared to the overall size of the structure.

#### *2.7. Differential Method*

In the differential encoding, which is a special case of the predictor where *α* = 1 and *β* = 0, the residual value is obtained by simply taking the difference between the reference band and the current band. For a particular pixel in the current band and the corresponding pixel in the reference band, *δ<sup>i</sup>* being the residual value, *yi* the actual value of the current band, and *xi* the value of the reference band, to encode, the following equation is used:

$$
\delta\_{\dot{i}} = \mathcal{Y}\_{\dot{i}} - \mathfrak{x}\_{\dot{i}}\ . \tag{6}
$$

To decode, the following equation is used:

$$y\_i = \delta\_i + x\_i \,. \tag{7}$$

Like the predictor, we can use the first band as the reference band and the next several bands can use this reference band to find the residual values. Again, the grouping is repeated up to the last band. For this coding method, only the group size (stored as a 2-byte short integer) needs to be saved.

#### *2.8. Related Work*

Since the publication of the proposals on *k*2-tree and *k*2-raster, more research has been done to extend the capabilities of the structures to 3D where the first and second dimensions represent the spatial element and the third dimension the time element.

Based on their previous research of *k*2-raster, Silva-Coira et al. [26] proposed a structure called Temporal *<sup>k</sup>*2-raster (<sup>T</sup> − *<sup>k</sup>*2raster) which represents a time-series of rasters. It takes advantage of the fact that in a time-series, the values in a matrix *M*<sup>1</sup> are very close to, if not the same as, the next matrix *M*<sup>2</sup> or even the one after that, *M*3, along the timeline. The matrices can then be grouped into *τ* time instants where the values of the elements of the first matrix in the group is subtracted from the corresponding ones in the current matrix. The result will be smaller integer values that would help form a more compact tree as there are likely to be more zeros in the tree than before. Their experimental results bear this out. When the *τ* value is small (*τ* = 4), the sizes are small. However, as would be expected, the results are not as favorable when the *τ* value becomes larger (*τ* = 50). Akin to the Temporal *k*2-raster, the differential encoding on *k*2-raster that we are proposing in this paper also exploits the similarity between neighboring matrices or bands in a hyperspectral image to form a more compact structure.

Another study on compact representation of raster images in a time-series was proposed earlier this year by Cruces et al. in [27]. This method is based on the 3D to 2D mapping of a raster where 3D tuples <*x*, *y*, *z*> are mapped into a 2D binary grid. That is, a raster of size *w* × *h* with values in a certain range, between 0 and *v* inclusive will have a binary matrix of *w* × *h* columns and *v*+1 rows. All the rasters will then be concatenated into a 3D cube and stored as a *k*3-tree.

#### **3. Results**

In this section we describe some of the experiments that were performed to show the use of compact data structures, prediction and differential encoding for real-time processing and compression. First, we show the results with other compression algorithms and techniques that are currently in use such as gzip, bzip2, xz, M-CALIC [15] and CCSDS 123.0-B-1 [9]. Then we compare the build time and the data access time for *k*2-raster with and without prediction and differential encoding. Next, we show the results of different rates in *k*2-raster that are produced as different k-values are applied. Similarly, the results of different group sizes for prediction and differential encoding are shown. Finally, the predictive method and the differential method are compared.

Experiments were conducted using hyperspectral images from different sensors: Atmospheric Infrared Sounder (AIRS), Airborne Visible/Infrared Imaging Spectrometer (AVIRIS), Compact Reconnaissance Imaging Spectrometer for Mars (CRISM), Hyperion, and Infrared Atmospheric Sounding Interferometer (IASI). Except for IASI, all of them are publicly available for download (http: //cwe.ccsds.org/sls/docs/sls-dc/123.0-B-Info/TestData). Table 1 gives more detailed information on these images. The table also shows the bit-rate reduction for using *k*2-raster with and without prediction. Performance in terms of bit rate and entropy is evaluated for them.

For best results in *k*2-raster for the testing images, we used the optimal *k*-value, and also in the case of the predictor and the differential encoder, the optimal group size for each image was used. The effects of using different *k*-values and different group sizes will be discussed and tested in two of the subsections below.

To build the structure of *k*2-raster and the cell query functions, a program in C was written. The algorithms presented in the paper by Ladra et al. [20] were the basis and reference for writing the code. The DACs software that was used in conjunction with our program is available at the Universidade da Coruña's Database Laboratory (Laboratorio de Bases de Datos) website (http://lbd. udc.es/research/DACS/). The package is called "DACs, optimization with no further restrictions". As for the predictive and differential methods, another C program was written to perform the tasks needed to give us the results that we will discuss below. All the code was compiled using gcc or g++ 5.4.0 20160609 with -Ofast optimization.


**Table 1.** Hyperspectral images used in our experiments. It also shows the bit rate and bit rate reduction using *k*2-raster with and without the predictor.

 *x* is the


**Table 1.** *Cont.*

The machine that these experiments ran on has an Intel Core 2 Duo CPU E7400 @2.80GHz with 3072KB of cache and 3GB of RAM. The operating system is Ubuntu 16.04.5 LTS with kernel 4.15.0-47-generic (64 bits).

To ensure that there was no loss of information, the image was reconstructed by reverse transformation and verified to be identical to the original image in the case of predictive and differential methods. For *k*2-raster, after saving the structure to disk, we made sure that the original image could be reconstructed from the saved data.

#### *3.1. Comparison with Other Compression Algorithms*

Both *k*2-raster with and without predictive and differential encoding were compared to other commonly-used compression algorithms such as gzip, bzip2, xz, and specialized algorithms such as M-CALIC and CCSDS 123.0-B-1. The results for the comparison are shown in Table 2 and depicted in Figure 12.

It can be seen that *k*2-raster alone already performed better than gzip. When it was used with the predictor, it produced a bit rate that was basically on a par with and sometimes better than other compression algorithms such as xz or bzip2. However, it could not attain the bit-rate level done by CCSDS 123.0-B-1 or M-CALIC. This was to be expected as both are specialized compression techniques, and CCSDS 123.0-B-1 is considered a baseline against which all compression algorithms for hyperspectral images are measured. Nevertheless, *k*2-raster provides direct access to the elements without full decompression, and this is undoubtedly the major advantage it has over all the aforementioned compression algorithms.

**Figure 12.** A rate (bpppb) comparison with other compression techniques.

**Table 2.** A rate (bpppb) comparison with other compression techniques. The optimal values for all compression algorithms (except for M-CALIC, CCSDS 123.0-B-1)arehighlightedinred.ResultsforCCSDS123.0-B-1arefrom[28].




#### *3.2. Build Time*

Both the time to build the *k*2-raster only and the time to build *k*2-raster with predictive and differential preprocessing were measured. They were then compared against the time to compress the data with gzip. The results are presented in Table 3. We can see that the build time for *k*2-raster only took half as long as with gzip. Comparing the predictive and the differential methods, the time difference is small although it generally took longer to build the former than the latter due to the additional time needed to compute the values of *α*ˆ and *β*ˆ. Both, however, still took less time to build than gzip compression.


**Table 3.** A comparison of build time (in seconds) using *k*2-raster only and *k*2-raster with predictive and differential methods.
