# Recursive Least Squares for Near-Lossless Hyperspectral Data Compression
## 2 Compression Scheme
### Loop Predictor  
Hyperspectral images can be regarded as a three-dimensional data. Let \(s_{z}(x,y)\) denote the value of the original pixel in the \(z\)th band at the \(x\)th row with the \(y\)th column. We also use \(s_{z}(n)\) to represent the \(n\)th pixel in band \(z\), where the notation \(n\) means the pixel is derived from \(n~{}=~{}NX*y~{}+~{}x\) in the spatial domain. \(NX\), \(NY\), and \(NZ\) provide the image's width, height, and number of bands. The spatial prediction estimate is computed using a causal, linear predictor for each pixel. To remove spatial correlation from the hyperspectral image, the preliminary estimate \(\hat{S}_{z}(n)\)of the target pixel \(S_{z}(n)\) is generated by averaging the pixels in the context window of the same band. The context window of the target pixel can be explained using Figure 2. The parameter \(r\) denotes the local context window's radius, and the target pixel points are represented in orange. The blue and green parts show the neighborhood windows with radii of one and three, respectively. Then, the spatial prediction error \(d_{z}(n)\) for the \(n\)th pixel point in the \(z\)th band is defined as Equation (1). \[d_{z}(n)=s_{z}(n)-\hat{S}_{z}(n). \tag{1}\]  
Note that in order to ensure the feasibility of the decompressor, the preliminary prediction error \(d_{z}(n)\) of the first spectrum is directly encoded with the entropy encoder that follows. The others are encoded after removing the inter-spectral redundancy. Figure 1: Compressor schematic. In the spectrum prediction process, the RLS filter input vector is formed by \(\mathbf{d}_{z,k}(n)=[d_{z-k}(n),\cdots,d_{z-1}(n)]^{T}\), where \(k\) is the number of history bands used to predict the current pixel, i.e., the prediction length. The corresponding weight vector is \(\mathbf{w}_{z,k}(n)=[w_{z-k}(n),\cdots,w_{z-1}(n)]^{T}\). Then, the RLS predictor is initialized as Equation (2). \[\mathbf{k}_{z}(0)=0,\mathbf{w}_{z}(0)=0,\mathbf{p}_{z}(0)=0. \tag{2}\]  
The spectrum prediction residual \(e_{z}(n)\) is calculated as Equation (3). \[e_{z}(n)=d_{z}(n)-\mathbf{d}_{z,k}(n)\mathbf{w}_{z,k}^{T}(n-1). \tag{3}\]  
The parameter's peak absolute error \(\Lambda\) determines the maximum allowable absolute difference between the original and reconstructed pixel values. Each predicted residual corresponds to a quantized residual \(q_{z}(n)\) defined by Equation (4). \[q_{z}(n)=sgn(e_{z}(n))\times\left\lfloor\frac{\Lambda+|e_{z}(n)|}{2\Lambda+1 }\right\rfloor, \tag{4}\]  
where the \(sgn(x)\) is a function that extracts the sign value of \(x\). For spectral images that need to be stored with absolute accuracy, a lossless compression mode can be used by setting \(\Lambda~{}=~{}0\). That is, \(q_{z}(n)=e_{z}(n)\), thus ensuring that the decoding process can accurately reconstruct the original sample. However, when using a non-zero peak absolute error, \(q_{z}(n)\) represents an approximation of the above prediction error, rather than the actual value. Since the image introduces distortion affected by the quantizer, the compressed code stream cannot be directly employed to reconstruct the sample. In order to guarantee synchronization with the decompression stage, the reconstruction value \(\widetilde{s}_{z}(n)\) should be calculated for each pixel, as shown in Equation (5). Then, \(\widetilde{s}_{z}(n)\) is used in the prediction process for the next pixel point to be measured. \[\widetilde{s}_{z}(n)=\delta_{z}(n)+\mathbf{d}_{z,k}(n)\mathbf{w}_{z,k}(n-1)+\widetilde {e}_{z}(n). \tag{5}\]  
where the center of the predicted residual reconstruction value \(\widetilde{e}_{z}\) is calculated by Equation (6). \[\widetilde{e}_{z}(n)=~{}q_{z}(n)(2\Lambda+1), \tag{6}\]  
The gain of RLS is  
\[\mathbf{k}_{z}^{T}(n)=\frac{\mathbf{p}_{z}(n-1)\mathbf{d}^{T}_{z}(n)}{1+d_{z}(n)\mathbf{p}(n-1 )_{z}\mathbf{d}^{T}_{z}(n)}, \tag{7}\]  
\[\mathbf{p}_{z}(n)=\mathbf{p}_{z}(n-1)-\mathbf{k}_{z}^{T}(n)\mathbf{d}_{z}(n)\mathbf{p}_{z}(n-1), \tag{8}\]  
\[d_{z}(n)=s_{z}(n)-\hat{S}_{z}(n). \tag{1}\]0 The context window of current pixel.