Entropy Coding (EC) [4] encompasses a whole series of coding techniques that exploit the statistical redundancy in data with the ultimate goal of finding a more compact representation, but without lossing information. EC is related to the definition of entropy in the context of the Information Theory [6]. In this area, the entropy quantifies the average amount of information represented by a data set, so that the higher the entropy, the better the efficiency of such representation (data).
All data (text, audio, image, video, etc.) compression techniques rely on EC to achieve an effective reduction of bits (of data). For example, JPEG uses a combination of Huffman Coding (see below) and Run-Length Encoding to represent the quantized DCT coefficients.
General speaking, data are sequences of symbols. There are basically two types of entropy encoders depending on how the symbols are processed:
A Huffman code [5, 1] is a prefix code that, for each code-word, allows to “navigate” through the so called Huffman tree from the trunk to one of its leaves, without uncertainty. The Huffman tree satisfies that \begin {equation} l(c(s)) = \lceil I(s)\rceil , \label {eq:huffman_performance} \end {equation} where \(l(c(s))\) is the length of the (Huffman) code-word, usually in bits of data, assigned to the symbol \(s\), and \(I(s)\) is the amount of information represented by \(s\), measured bits of information [6].
Notice that the minimum number of bits that can be used for representing a symbol (using Huffman) is 1, which can be a inefficient when the length of the alphabet is small.1 Another drawback of HC is that the Huffman tree must be updated each time the probabilistic model is updated, action very frequent when using adaptive models.
In an arithmetic codec [2, 1], the number of bits of data that are used for representing symbols match exactly the number of bits of information provided by the symbols, i.e, \begin {equation} l(c(s)) = I(s). \end {equation}
This also means that, even if the size of the alphabet is small, the coding performance of an arithmetic code is optimal, although this optimality is only fully satisfied if the number of symbols to encode is infinite. Notice also that, if the alphabet is large, the encoding performance difference between a Huffman code (or any other prefix code) and an arithmetic code, vanishes.
zlib is based on DEFLATE, which in turn is based on LZ77 [7, 1] and Huffman coding. Therefore, zlib exploits the repetition of symbols and also, the 0-order statistical redundancy2. One of the main advantages of zlib is that is quite fast compared to symbol encoders such as HC and AC.
Nowadays, zlib is a keystone in data manipulation because it is the basic library used in such important applications as Zip and Gzip.
PNG [8] (pronounced “ping”) is a dictionary-based (string encoding) lossless image compression format used for representing digital images and videos [3] in III... format [?]. The entropy encoder of PNG is based on HC and LZSS, and a pixel predictor that removes the spatial redundancy.
We must bear in mind that as such an image compressor, we can only interact with PNG at the image level, that is, it only accepts images (in shades of gray or in color, with the possibility of an alpha channel), and only returns images.
[1] Vicente González-Ruiz. Compresión Reversible y Transmisión de Imágenes. PhD thesis, University of Almería (UAL), 2000.
[2] V. González-Ruiz. Arithmetic Coding.
[3] V. González-Ruiz. Digital Images and Videos.
[4] V. González-Ruiz. Entropy Coding.
[5] V. González-Ruiz. Huffman Coding.
[6] V. González-Ruiz. Information Theory.
[7] V. González-Ruiz. Lempel-Ziv-Welch.
[8] V. González-Ruiz. PNG (Portable Network Graphics).
[9] V. González-Ruiz. Run-Length Encoding.
[10] Nelson M. and Gailly J. The Data Compression Book. M&T Books, 1996.