CS475 – Networks Lecture 24 Chapter 7: End-to-End Data Assignments • Reading for Lecture 25: Sections 9.1-9.2 7.2 Data Compression Data compression can allow us to send data at a faster rate than Compression and decompression are often time consuming. seemingly supported by the network. Compression can, for Greater _____________________ can only be achieved if example, allow us to send a 10 Mbps video stream over a 1 Mbs link. x / Bc + x / (r Bn) < x / Bn where x represents the amount of data (uncompressed), r is the Compression algorithms can be categorized as lossy or lossless. compression ratio, Bc is the bandwidth at which data can be run Greater compression _______________ can be achieved with through the compressor/decompressor and Bn is the network lossy algoritms. The lost data may not be noticeable in images bandwidth. or audio or video streams. 7.2.1 Lossless Compression - Run Length Encoding (RLE) In RLE, consecutive occurrences of a symbol are replaced with a be achieved. It is used to transmit ________________. If there copy of the symbol and a count. The string AAABBCDDDD is not a lot of adjacent identical data, RLE actually can increase would be encoded as 3A2B1C4D (an 80% compression ratio). the size of a file. RLE works well on scanned text images where 8 to 1 rates can 7.2.1 Lossless Compression - Differential Pulse Code Modulation In DPCM, a reference symbol is output and then the A variation gives ________________ encoding where each ____________________ between each symbol and the reference symbol is encoded as the difference from the previous one. is output. AAABBCDDDD would become A001011000. Encoding the The string AAABBCDDDD would be output as A0001123333. difference using only one bit gives a compression ratio of 21%. Differences between 0 and 3 can be encoded using only 2 bits so Delta encoding may be following by RLE since there may be the compression ratio is 35%. When the difference becomes too long strings of 0s. Delta encoding works well when adjacent large a new reference symbol is output. pixels in an image are similar. 7.2.1 Lossless Compression - Dictionary Methods The UNIX __________________ command uses a variation of The Graphical Interchange Format (_____________) image uses the Limpel-Ziv (LZ) algorithm which is a dictionary based 8-bit pixels to index into a 256 color 24-bit palette. The image is method. compressed using LZ with common sequences of pixels making With this approach a group of symbols (a word) is replaced by up the dictionary. its index into a dictionary. LZ generates the dictionary Patent restrictions on the LZ algorithm spurred development in adaptively and must transmit the dictionary along with the 1995 of the Portable Network Graphics (PNG) format as a compressed data. replacement format for images on the web. The patent expired in 2003. 11/17/2011 Page 1 of 4 7.2.2 Image Compression (JPEG) 7.2.2 Image Compression (JPEG) - DCT Phase The JPEG (Joint Photographic Expert Group) image format uses To simplify the discussion assume that we are working only with a __________________ compression algorithm that offers better 8-bit grayscale images where 0 is white and 255 is black. ratios than GIF or PNG. JPEG is related to MPEG which is a In the discrete cosine transform (DCT) phase an 8 x 8 matrix of video data format. pixel values is converted to an 8 x 8 matrix of frequency JPEG compression occurs in three phases. The image is fed coefficients. Low frequency coefficients define _____________ through the phases one 8 x 8 block at a time. image feature while high frequency coefficients correspond to the fine details. The DCT and its inverse are defined by N−1 N −1 1 DCT i , j = C i C j ∑ ∑ pixel x , y 2N x=0 x=0 2 x1 i 2 y1 j cos cos 2N 2N [ pixel x , y= ] [ 1 2N cos { 1 where C i= 2 1 [ The frequency coefficient at (0, 0) is the DC coefficient and is the ___________________ of the 64 pixel values. The other ] coefficients correspond to higher frequencies and to finer and N −1 N −1 finer detail. ∑ ∑ C iC j DCT i , j i =0 j =0 ] [ 2 x1i 2 y1 j cos 2N 2N ] The DCT is lossless. The image can be exactly reconstructed from the coefficients using the inverse transform. It is in the if i =0 Quantization Phase where loss is introduced. if i 0 7.2.2 Image Compression (JPEG) - Quantization Phase To see how quantization works imagine truncating numbers less Instead of using the same quantum value for all 64 freq. than 100 to multiples of 10. For example, the numbers 45, 98, coefficients, JPEG uses quantization tables. An example table is: [ 23, 66 and 7 would become 4, 9, 2, 6 and 0. These numbers can 3 5 7 9 Quantum= 11 13 15 17 be encoded using only 4 bits instead of 7. The truncation operation is equivalent to dividing each of the original numbers by a ________________ (10) using integer division. 5 7 9 11 13 15 17 19 7 9 11 13 15 17 19 21 9 11 13 15 17 19 21 23 11 13 15 17 19 21 23 25 13 15 17 19 21 23 25 27 15 17 19 21 23 25 27 29 17 19 21 23 25 27 29 31 ] The quantized frequency coefficient values are computed using: QuantizedValue i , j = IntegerRound DCTi , j / Quantum i , j 11/17/2011 Page 2 of 4 7.2.2 Image Compression (JPEG) - Encoding Phase 7.2.2 Image Compression (JPEG) -Color Images A variant of RLE is used to compress an 8 x 8 block along a A color image can be thought of as being made up of separate zigzag path. The individual coefficients are encoded using a red, green and blue images. This is known as the RGB ________________ code representation. JPEG typically uses the YUV (luminance and (short codes are assigned _______________________) representation. to the most frequently Each of the Y, U, and V images is processed as described for a occurring coefficients). grayscale image. Zigzag traversal of the JPEG is capable of compressing 24-bit images by an quantized frequency approximately 30-to-1 ratio. coefficients for RLE. 7.2.3 Video Compression (MPEG) Video can be thought of as a succession of still images or By additionally removing the _____________________ frames. Individual frames can be compressed using a DCT- information that is present in successive frames compression based technique as with JPEG. ratios on the order of 150-to-1 can be achieved. 7.2.3 Video Compression (MPEG) - Frame Types MPEG takes a video stream and produces intrapicture (I), components are downsampled to an 8 x 8 block. ______________________ picture (P) and bidirectional predicted picture (B) frames. A _______________________ in a B frame is represented with a 4-tuple: (1) coordinates (x and y) for the macroblock, (2) a motion vector (xp and yp) relative to the previous reference, (3) a I frames can be considered to be JPEG compressed frames. They are self-contained. P and B frames specify motion vector (xf and yf) relative to the next reference, and (4) a delta (δ) for each pixel in the macroblock. The pixel value in the ______________________ relative to an I frame. current frame is computed using: Fc(x, y) = (Fp(x+xp, y+yp)+Fn(x+xf, y+yf))/2 + δ(x, y) 16 x 16 blocks of pixels are used in MPEG. The U and V 11/17/2011 Page 3 of 4 7.2.4 Transmitting MPEG over a Network The MPEG specification specifies the format for a video stream but does not specify how the stream is broken into network packets. An MPEG main profile is a nested structure. At the top level the video stream is broken into groups of pictures (GOP) separated by a SeqHdr. The SeqHdr contains a quantization _____________________ for the I frame and one for the B and P frames. A GOP consists of pictures (I, B, and P frames) and pictures are By using UDP and breaking the stream at selected points broken into slices (a region of the picture). A slice consists of a (macroblock boundaries) we can limit the loss in picture quality macroblock. A macroblock is made up of six 8 x 8 blocks (one due to a lost network packet. This is an example of application each for the U and V components and 4 for the Y component level framing. which is 16 x 16). The video encoding method may depend on MPEG allows the frame rate, ____________________, mix of ____________________ as well as bandwidth. For interactive frame types, and quantization to change between GOPs, videoconferencing (where low latency is desirable) an encoding allowing picture quality to be traded for network bandwidth using only I and P frames (I P P P P I) may be preferable to one adaptively. also using B frames (I B B B B P B B B B I). 7.2.5 Audio Compression (MP3) CD quality sound requires sampling at 44.1 kHz using 16-bit MPEG also defines audio compression formats, the most popular samples. A stereo stream implies a bit rate of is Layer III (MP3) which reduces BW requirements to 128 Kbps 2 x 44100 x 16 = 1.41 Mbps MP3 splits audio into frequency subbands. The subbands are _________________________ and error correction require broken into blocks, transformed (DCT), quantized and Huffman sending 49 bits instead of 16 resulting in encoded (all similar to video compression). 49/16 x 1.41 Mbps = 4.32 Mbps The audio frames are _____________________ with video frames to form a complete MPEG stream. In Class Exercise To be submitted as part of Homework 8 • Problems 7.25 and 7.26 • 11/17/2011 Notes for these problems on the course webpage Page 4 of 4