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:
x0←0, // the initial value to be XORed with the first element of x.
nZ0←0, // initialize the first nonzero value with 0.
cnt←1, // counts the number of consecutive runs.
PO2←2, // to calculate the required number of bits for each run.
nVar←11, // 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 ⊕ xi−1 // perform exclusive-or operation.

If xored>0 Then
nZi←1
2. Calculation of the integral part
MSH← the leftmost ⌈n/2⌉ bits of xored
Q←2n/2
seed←(MSH+Q)≫1
riceCode←mappedRice(seed)
vecRice.add(riceCode)
3. Calculation of the fractional part
m←log2⁡2⋅seed
Fr←xored−seed2 // The fraction encoded as the distance between the xored value and the squared value of the seed
        If Fr>0 Then
        Fr ←Fr−1
        Else
        Fr ←Unary(seed)
        seed ←0
        End If
Frout← the rightmost m bits of Fr
vecFr.add(Frout)
Else
nZi←0
End If

4. Run length encoding of nZ
If nZi=nZi−1 Then
cnt←cnt+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