Skip to main content
. 2024 Apr 5;26(4):316. doi: 10.3390/e26040316
Algorithm 2. Pseudocode for the compressor part of the proposed lossless compression.
Input: x // hyperspectral data
Outputs:
vecRice, // a vector that stores the calculated seed values.
vecFrac, // a vector that stores the calculated fractions.
vecRLE, // a vector that holds the counts of consecutive runs of zero and nonzero values.
vecUnary. // a vector that holds the variable unary codes corresponding to the number of bits of each count.
Initializations:
x00, // the initial value to be XORed with the first element of x.
nZ00, // initialize the first nonzero value with 0.
cnt1, // counts the number of consecutive runs.
PO22, // to calculate the required number of bits for each run.
nVar11, // the required number of bits for each run.
n the number of bits required to represent x.
done  0

For all xi in x Do
1. Preprocessing
xored  xi  xi1 // perform exclusive-or operation.

If xored>0 Then
nZi1
2. Calculation of the integral part
MSH the leftmost n/2 bits of xored
Q2n/2
seed(MSH+Q)1
riceCodemappedRice(seed)
vecRice.add(riceCode)
3. Calculation of the fractional part
mlog22seed
Frxoredseed2 // The fraction encoded as the distance between the xored value and the squared value of the seed
        If Fr>0 Then
        Fr Fr1
        Else
        Fr Unary(seed)
        seed 0
        End If
Frout the rightmost m bits of Fr
vecFr.add(Frout)
Else
nZi0
End If

4. Run length encoding of nZ
If nZi=nZi1 Then
cntcnt+1
        If cnt=PO2 Then
        PO2  PO2 1
        nVar nVar+1
        End If
Else
vecRLE.add(cnt)
vecUnary.add(nVar)
cnt  1
PO2  2
End If
End Do

If done Then
vecRLE.add(cnt)
vecUnary.add(nVar)
End If