Golomb coding is a lossless data compression method using a family of data compression codes invented by Solomon W. Golomb in the 1960s. Alphabets following a geometric distribution will have a Golomb code as an optimal prefix code, making Golomb coding highly suitable for situations in which the occurrence of small values in the input stream is significantly more likely than large values.
Rice coding Rice coding (invented by Robert F. Rice) denotes using a subset of the family of Golomb codes to produce a simpler (but possibly suboptimal) prefix code. Rice used this set of codes in an adaptive coding scheme; "Rice coding" can refer either to that adaptive scheme or to using that subset of Golomb codes. Whereas a Golomb code has a tunable parameter that can be any positive integer value, Rice codes are those in which the tunable parameter is a power of two. This makes Rice codes convenient for use on a computer, since multiplication and division by 2 can be implemented more efficiently in binary arithmetic. Rice was motivated to propose this simpler subset due to the fact that geometric distributions are often varying with time, not precisely known, or both, so selecting the seemingly optimal code might not be very advantageous. Rice coding is used as the entropy encoding stage in a number of lossless image compression and audio data compression methods.
Overview
Construction of codes Golomb coding uses a tunable parameter M to divide an input value x into two parts: q, the result of a division by M, and r, the remainder. The quotient is sent in unary coding, followed by the remainder in truncated binary encoding. When M = 1 {\displaystyle M=1} , Golomb coding is equivalent to unary coding. Golomb–Rice codes can be thought of as codes that indicate a number by the position of the bin (q), and the offset within the bin (r). The example figure shows the position q and offset r for the encoding of integer x using Golomb–Rice parameter M = 3, with source probabilities following a geometric distribution with p(0) = 0.2. Formally, the two parts are given by the following expression, where x is the nonnegative integer being encoded:
q = ⌊ x M ⌋ {\displaystyle q=\left\lfloor {\frac {x}{M}}\right\rfloor }
and
r = x − q M . {\displaystyle r=x-qM.}
Both q and r will be encoded using variable numbers of bits: q by a unary code, and r by b bits for Rice code, or a choice between b and b+1 bits for Golomb code (i.e. M is not a power of 2), with b = ⌊ log 2 ( M ) ⌋ {\displaystyle b=\lfloor \log _{2}(M)\rfloor } . If r < 2 b + 1 − M {\displaystyle r<2^{b+1}-M} , then use b bits to encode r; otherwise, use b+1 bits to encode r. Clearly, b = log 2 ( M ) {\displaystyle b=\log _{2}(M)} if M is a power of 2 and we can encode all values of r with b bits. The integer x treated by Golomb was the run length of a Bernoulli process, which has a geometric distribution starting at 0. The best choice of parameter M is a function of the corresponding Bernoulli process, which is parameterized by p = P ( x = 0 ) {\displaystyle p=P(x=0)} the probability of success in a given Bernoulli trial. M is either the median of the distribution or the median ±1. It can be determined by these inequalities:
( 1 − p ) M + ( 1 − p ) M + 1 ≤ 1 < ( 1 − p ) M − 1 + ( 1 − p ) M , {\displaystyle (1-p)^{M}+(1-p)^{M+1}\leq 1<(1-p)^{M-1}+(1-p)^{M},}
which are solved by
M = ⌈ − log ( 2 − p ) log ( 1 − p ) ⌉ . {\displaystyle M=\left\lceil -{\frac {\log(2-p)}{\log(1-p)}}\right\rceil .}
For the example with p(0) = 0.2:
M = ⌈ − log ( 1.8 ) log ( 0.8 ) ⌉ = ⌈ 2.634 ⌉ = 3. {\displaystyle M=\left\lceil -{\frac {\log(1.8)}{\log(0.8)}}\right\rceil =\left\lceil 2.634\right\rceil =3.}
The Golomb code for this distribution is equivalent to the Huffman code for the same probabilities, if it were possible to compute the Huffman code for the infinite set of source values.
… excerpt ends here. Continue reading the full article.



