· , sN} is called an alphabet. • Each si ∈ A is called a symbol. • A string over the alphabet is a sequence of symbols, e.g. s11 s4 s105 s105 s47 s86 s86 s3 · · · s30. • A codeword is a sequence of bits that represents a symbol or string. e.g. 1011000010110111101. • pi = p(si ) is the probability of occurrence of symbol si in a string. • Li is the length of the codeword for si in bits. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 6/14
same length (number of bits), e.g., letters A through H encoded as 3-bit binary numbers. A ↔ 000, B ↔ 001, C ↔ 010, · · · , H ↔ 111 • Variable length: different codewords may have different lengths depending on, for example, their probability of occurrence. A ↔ 0, B ↔ 10, 110, · · · , H ↔ 11111110 • This variable length code is a prefix code: no code is the prefix of another code. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 6/14
by a small number of bits and lowly probable values by relatively more number of bits • Coding 1. Find the probabilities of the occurrence of each value of the image. 2. Starting from the lowest probability, pair the two of the lowest probabilities to get a binary tree. 3. Assign 0 to leaf to the left side of a branch and 1 to that in the right side or vice versa. 4. Repeat steps 2 and 3, until all the values are placed. 5. Read the codes from the root of the tree to the leaf node where the value is placed. • Decoding: looking at the first few characters until a code corresponding to a value is found. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 7/14
unpredictability of a random variable or data source. • Introduced by Claude Shannon in 1948, it quantifies the theoretical minimum number of bits per pixel (bpp) for compressing by a lossless compression algorithm. • The entropy H(X) of a discrete random variable X is H(X) = − n i=1 p(xi ) log 2 p(xi ) • log: Additivity of independent events H(X, Y ) = H(X) + H(Y ) • Base 2 of the logarithm: entropy measured in bits NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 8/14
2 8 15 15 2 15 15 8 13 2 • Theoretical minimum number of bits required for lossless compression • Entropy = • The actual value of the first method = • The actual value of the second method = NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 8/14
2 8 15 15 2 15 15 8 13 2 • Theoretical minimum number of bits required for lossless compression • Entropy = 2.2272 • The actual value of the first method = 2.375 • The actual value of the second method = 2.25 NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 8/14
a 1-level 2-D Haar DWT using a 2-stage filter bank NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 10/14
a 1-level 2-D Haar IDWT using a 2-stage filter bank NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 10/14
is level shifted by subtracting 128 (0.5 times the maximum gray-level value) 44 60 61 58 50 59 61 64 60 62 68 69 63 65 69 71 • This ensures that the DWT coefficients are more evenly distributed around zero and quantization will be more effective. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 11/14
quantized levels are assumed to be −64 to 63. The maximum value of the coefficients is X(1, 1) = 138.5. Therefore, the quantization step is 138.5/63 = 2.1984. 48 55 -5 0 56 63 0 0 -1 -1 -1 1 -1 0 0 0 • A high quantization step will result in more compression, but the quality of the reconstructed image will be low. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 11/14
4 × 4 matrix is converted to a 1 × 16 vector by arranging the values in the zigzag order (to help getting a high run-length of zeros). • The approximation coefficients are followed by the H, V, and D detail coefficients. {48, 55, 56, 63, −5, 0, 0, 0, −1, −1, −1, 0, −1, 1, 0, 0} NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 11/14
code • The compressed image requires 42 bits. • The compression ratio is C = 128/42 = 3.0476. • The bits per pixel is bpp = 8/3.0476 = 2.6250. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 11/14
is decoded using the dictionary and the resulting 1-D vector is converted to the 4 × 4 matrix. The values are multiplied by the quantization step to get 105.5238 120.9127 -10.9921 0 123.1111 138.5 0 0 -2.1984 -2.1984 -2.1984 -2.1984 -2.1984 0 0 0 NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 11/14
commonly used method of lossy compression for digital images. • Tasked in the late 1980’s to generate a general-purpose standard for compression of almost all continuous tone and still-image applications. • The main idea is to transform the image into a frequency domain, quantize it, and then encode it. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 13/14
sensitive to color details. • Reduce the resolution of Cb and Cr components. • Typically 2:1 horizontal and vertical downsampling. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 13/14
DCT to 8x8 blocks of the image. • Transforms spatial domain to frequency domain. Most of the energy is concentrated in a few low-frequency components. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 13/14
by a quantization value. • Round to the nearest integer. • Reduces the number of bits needed to store the coefficients. • The quantization matrix is chosen based on human visual perception. The human eye is more sensitive to changes in low frequencies (smooth areas) and less sensitive to high frequencies (sharp details). A quality factor (Q-factor) can be applied to scale the entire matrix. Larger quantization steps, more zero coefficients, and smaller file sizes. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 13/14
Arithmetic coding. • Further reduces the size of the data. • Takes advantage of the statistical properties of the quantized coefficients. • The values are arranged in a zig-zag order to group similar coefficients together, which improves compression. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 13/14
compression algorithm and the first one based on the DWT2. Analyze each step and evaluate the results of the compression. NHSM - 4th year: Digital Image Processing - Compression (Week 6) - M. Hachama ([email protected]) 14/14