Presentation is loading. Please wait.

Presentation is loading. Please wait.

Image Coding and Compression

Similar presentations


Presentation on theme: "Image Coding and Compression"— Presentation transcript:

1 Image Coding and Compression
Introduction to Digital Image Processing with MATLAB® Asia Edition McAndrew‧Wang‧Tseng Chapter 14: Image Coding and Compression © 2010 Cengage Learning Engineering. All Rights Reserved.

2 14.1 Lossless and Lossy Compression
It is thus important for both reasons of storage and file transfer to make these file sizes smaller, if possible It will be necessary to distinguish between two different classes of compression methods: Lossless compression, where all the information is retained Lossy compression, where some information is lost © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.403

3 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.2 Huffman Coding The average number of bits per pixel can be calculated easily as the expected value (in a probabilistic sense): © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.404

4 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.2 Huffman Coding Determine the probabilities of each gray value in the image Form a binary tree by adding probabilities two at a time, always taking the two lowest available values Now assign 0 and 1 arbitrarily to each branch of the tree from its apex Read the codes from the top down © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.404

5 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.1 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.405

6 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.2 Huffman Coding © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.405

7 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.2 Huffman Coding We can evaluate the average number of bits per pixel as an expected value Huffman codes are uniquely decodable © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.406

8 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.3 Run-length Encoding Run-length encoding (RLE) is based on a simple idea: to encode strings of 0s and 1s by the number of repetitions in each string Encode each line separately starting with the number of 0s (binary image) © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.407

9 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.3 Run-length Encoding Encode each row as a list of pairs of numbers, the first number in each pair giving the starting position of a run of 1s and the second number its length Grayscale images can be encoded by breaking them up into their bit planes © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.407

10 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.3 Run-length Encoding Each plane can then be encoded separately using our chosen implementation of RLE © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.407

11 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.3 Run-length Encoding However, small changes of gray value may cause significant changes in bits To overcome this difficulty, we may encode the gray values with their binary Gray codes A Gray code is an ordering of all binary strings of a given length so that there is only one bit change between one string and the next © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.408

12 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.3 Run-length Encoding 4-bit gray codes Binary bit plane Gray codes © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.408

13 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.3 Run-length Encoding Run-length Encoding in MATLAB © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.409

14 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.3 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.410

15 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.3 Run-length Encoding We can reduce the size of the output by storing it using the data type uint16 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.410

16 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.3 Run-length Encoding © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.411

17 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm Lossy compression trades some acceptable data loss for greater rates of compression The algorithm developed by the Joint Photographic Experts Group (JPEG) has become one of the most popular It uses transform coding, where the coding is done not on the pixel values themselves, but on a transform © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.411

18 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm discrete cosine transform (DCT) In the JPEG algorithm it is applied only to 8 × 8 blocks If f(j, k) is one such block, then the forward (2-D) DCT is defined as The corresponding inverse DCT as © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.412

19 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm where C(w) is defined as The DCT has a number of properties that make it particularly suitable for compression: It is real-valued, so there is no need to manipulate complex numbers © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.412

20 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm It has a high information-packing ability because it packs large amounts of information into a small number of coefficients It can be implemented very efficiently in hardware Like the FFT, there is a “fast” version of the transform that maximizes efficiency The basis values are independent of the data [7] © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.412

21 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.412

22 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.4 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.414

23 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm The JPEG baseline compression scheme is applied as follows: The image is divided into 8 × 8 blocks, with each block transformed and compressed separately For a given block, the values are shifted by subtracting 128 from each value The DCT is applied to this shifted block The DCT values are normalized by dividing by a normalization Matrix Q. It is this normalization that provides the compression by making most of the elements of the block zero © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.413

24 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm This matrix is formed into a vector by reading off all nonzero values from the top left in a zigzag fashion: The first coefficients of each vector are encoded by listing the difference between each value and the values from the previous block. This helps keep all values (except for the first) small These values are then compressed using RLE All other values (known as the AC coefficients) are compressed using a Huffman coding © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.414

25 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm To decompress, the steps above are applied in reverse The Huffman encoding and RLE can be decoded with no loss of information The vector is read back into an 8 × 8 matrix The matrix is multiplied by the normalization matrix The inverse DCT is applied to the result The result is shifted back by 128 to obtain the original image block The normalization matrix © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.415

26 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.415

27 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.416

28 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm The normalization matrix © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.416

29 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm Where EOB signifies the end of the block. By this stage we have reduced an 8 × 8 block to a vector of length 21, containing only small values To uncompress © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.417

30 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.417

31 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm It can be seen that these values are very close to the values in the original block. The differences between original and reconstructed values are The algorithm works best on regions of low frequency; in such cases the original block can be reconstructed with only very small errors © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.418

32 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.5 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.419

33 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.6 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.420

34 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.7 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.421

35 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.8 Suppose we take our extra parameter n to be 2. This has the effect of doubling each value in the normalization matrix, thus should set more of the DCT values to 0: © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.421

36 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.421

37 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.9 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.422

38 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.10 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.423

39 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 14.11~14.13 © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.423

40 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm We have seen how changing the compression rate may affect the output. The JPEG algorithm, however, is particularly designed for storage The output vector is further encoded using Huffman coding DC (first value) k contains all elements x whose absolute value satisfies © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.424

41 © 2010 Cengage Learning Engineering. All Rights Reserved.
14.4 The JPEG Algorithm e.g. © 2010 Cengage Learning Engineering. All Rights Reserved. Ch14-p.425


Download ppt "Image Coding and Compression"

Similar presentations


Ads by Google